1 17 18 package org.apache.tools.ant.taskdefs.optional.depend; 19 20 import java.io.File ; 21 import java.io.FileReader ; 22 import java.io.IOException ; 23 import java.util.Date ; 24 import java.util.Vector ; 25 import java.util.Enumeration ; 26 import java.util.Hashtable ; 27 import org.apache.tools.ant.BuildFileTest; 28 import org.apache.tools.ant.Project; 29 import org.apache.tools.ant.types.FileSet; 30 import org.apache.tools.ant.DirectoryScanner; 31 32 36 public class DependTest extends BuildFileTest { 37 public static final String RESULT_FILESET = "result"; 38 39 public static final String TEST_BUILD_FILE 40 = "src/etc/testcases/taskdefs/optional/depend/depend.xml"; 41 42 public DependTest(String name) { 43 super(name); 44 } 45 46 public void setUp() { 47 configureProject(TEST_BUILD_FILE); 48 } 49 50 public void tearDown() { 51 executeTarget("clean"); 52 } 53 54 57 public void testDirect() { 58 executeTarget("testdirect"); 59 Hashtable files = getResultFiles(); 60 assertEquals("Depend did not leave correct number of files", 3, 61 files.size()); 62 assertTrue("Result did not contain A.class", 63 files.containsKey("A.class")); 64 assertTrue("Result did not contain D.class", 65 files.containsKey("D.class")); 66 } 67 68 71 public void testClosure() { 72 executeTarget("testclosure"); 73 Hashtable files = getResultFiles(); 74 assertTrue("Depend did not leave correct number of files", 75 files.size() <= 2); 76 assertTrue("Result did not contain D.class", 77 files.containsKey("D.class")); 78 } 79 80 83 public void testInner() { 84 executeTarget("testinner"); 85 assertEquals("Depend did not leave correct number of files", 0, 86 getResultFiles().size()); 87 } 88 89 93 public void testInnerInner() { 94 executeTarget("testinnerinner"); 95 assertEquals("Depend did not leave correct number of files", 0, 96 getResultFiles().size()); 97 } 98 99 102 public void testNoSource() { 103 expectBuildExceptionContaining("testnosource", 104 "No source specified", "srcdir attribute must be set"); 105 } 106 107 110 public void testEmptySource() { 111 expectBuildExceptionContaining("testemptysource", 112 "No source specified", "srcdir attribute must be non-empty"); 113 } 114 115 121 private Hashtable getResultFiles() { 122 FileSet resultFileSet = (FileSet) project.getReference(RESULT_FILESET); 123 DirectoryScanner scanner = resultFileSet.getDirectoryScanner(project); 124 String [] scannedFiles = scanner.getIncludedFiles(); 125 Hashtable files = new Hashtable (); 126 for (int i = 0; i < scannedFiles.length; ++i) { 127 files.put(scannedFiles[i], scannedFiles[i]); 128 } 129 return files; 130 } 131 132 133 137 public void testInnerClosure() { 138 executeTarget("testinnerclosure"); 139 assertEquals("Depend did not leave correct number of files", 4, 140 getResultFiles().size()); 141 } 142 143 146 public void testCache() { 147 executeTarget("testcache"); 148 } 149 150 153 public void testNonPublic() { 154 executeTarget("testnonpublic"); 155 String log = getLog(); 156 assertTrue("Expected warning about APrivate", 157 log.indexOf("The class APrivate in file") != -1); 158 assertTrue("but has not been deleted because its source file " 159 + "could not be determined", 160 log.indexOf("The class APrivate in file") != -1); 161 } 162 163 } 164 | Popular Tags |