1 package net.sourceforge.cruisecontrol.bootstrappers; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 9 import junit.framework.TestCase; 10 import net.sourceforge.cruisecontrol.CruiseControlException; 11 12 public class LockFileBootstrapperTest extends TestCase { 13 14 private LockFileBootstrapper bootstrapper; 15 private List filesToDelete; 16 17 protected void setUp() { 18 bootstrapper = new LockFileBootstrapper(); 19 filesToDelete = new ArrayList (); 20 } 21 22 protected void tearDown() throws Exception { 23 for (Iterator iter = filesToDelete.iterator(); iter.hasNext();) { 24 File file = (File ) iter.next(); 25 file.delete(); 26 } 27 bootstrapper = null; 28 filesToDelete = null; 29 } 30 31 public void testAttemptToCreateLockFile() throws IOException , CruiseControlException { 32 File lock = File.createTempFile("test", ".lck"); 33 filesToDelete.add(lock); 34 lock.delete(); 35 assertFalse(lock.exists()); 36 37 bootstrapper.setLockFile(lock.getAbsolutePath()); 38 39 bootstrapper.bootstrap(); 40 assertTrue(lock.exists()); 41 42 try { 43 bootstrapper.bootstrap(); 44 fail("should throw exception when lock already exists"); 45 } catch (CruiseControlException expected) { 46 } 47 } 48 49 public void testValidate() throws CruiseControlException { 50 try { 51 bootstrapper.validate(); 52 fail("should throw exception when lock file not set"); 53 } catch (CruiseControlException expected) { 54 } 55 56 bootstrapper.setLockFile("delete.me"); 57 bootstrapper.validate(); 58 } 59 60 } 61 | Popular Tags |