1 4 package com.tc.test; 5 6 import org.apache.commons.io.FileUtils; 7 8 import java.io.File ; 9 10 import junit.framework.TestCase; 11 12 15 public class TempDirectoryHelperTest extends TestCase { 16 17 private File baseFile; 18 private File expectedDir; 19 private TempDirectoryHelper helper; 20 21 public void setUp() throws Exception { 22 23 String root = TestConfigObject.getInstance().tempDirectoryRoot() + File.separator + "temp-TempDirectoryHelperTest"; 24 this.baseFile = new File (root); 25 if (!this.baseFile.exists()) assertTrue(this.baseFile.mkdirs()); 26 this.expectedDir = new File (this.baseFile, ClassBasedDirectoryTreeTest.joinWithFileSeparator(new String [] { "com", 27 "tc", "test", "TempDirectoryHelperTest" })); 28 if (this.expectedDir.exists()) FileUtils.deleteDirectory(this.expectedDir); 29 this.helper = new TempDirectoryHelper(getClass(), root, true); 30 } 31 32 public void testCreates() throws Exception { 33 assertFalse(this.expectedDir.exists()); 34 35 File theDir = this.helper.getDirectory(); 36 assertEquals(this.expectedDir.getAbsolutePath(), theDir.getAbsolutePath()); 37 38 assertTrue(this.expectedDir.exists()); 39 assertTrue(this.expectedDir.isDirectory()); 40 } 41 42 public void testCleans() throws Exception { 43 File theFile = new File (this.expectedDir, "foo.txt"); 44 assertTrue(this.expectedDir.mkdirs()); 45 assertTrue(theFile.createNewFile()); 46 assertTrue(theFile.exists()); 47 48 this.helper.getDirectory(); 49 assertFalse(theFile.exists()); 50 } 51 52 public void testDoesNotReclean() throws Exception { 53 this.helper.getDirectory(); 54 55 File theFile = new File (this.expectedDir, "foo.txt"); 56 assertTrue(theFile.createNewFile()); 57 assertTrue(theFile.exists()); 58 59 this.helper.getDirectory(); 60 assertTrue(theFile.exists()); 61 } 62 63 public void testGetFile() throws Exception { 64 File theFile = new File (this.expectedDir, "foo.txt"); 65 assertTrue(this.expectedDir.mkdirs()); 66 assertTrue(theFile.createNewFile()); 67 assertTrue(theFile.exists()); 68 69 File otherFile = this.helper.getFile("bar.txt"); 70 assertFalse(theFile.exists()); 71 assertFalse(otherFile.exists()); 72 73 assertTrue(theFile.createNewFile()); 74 assertTrue(otherFile.createNewFile()); 75 76 File thirdFile = this.helper.getFile("baz.txt"); 77 assertTrue(theFile.exists()); 78 assertTrue(otherFile.exists()); 79 assertFalse(thirdFile.exists()); 80 assertTrue(thirdFile.createNewFile()); 81 assertTrue(thirdFile.exists()); 82 83 File theDir = this.helper.getDirectory(); 84 assertTrue(theFile.exists()); 85 assertTrue(otherFile.exists()); 86 assertEquals(theDir.getAbsolutePath(), theFile.getParentFile().getAbsolutePath()); 87 } 88 89 } | Popular Tags |