1 package junitx.util; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 6 import java.io.File ; 7 import java.util.List ; 8 9 13 public class DirectorySuiteBuilderTest 14 extends TestCase { 15 16 public DirectorySuiteBuilderTest(String name) { 17 super(name); 18 } 19 20 public String getFilename() { 21 return "build/classes-example"; 22 } 23 24 27 public void testBuildSampleA() 28 throws Exception { 29 DirectorySuiteBuilder builder = new DirectorySuiteBuilder(); 30 TestFilter filter = new SimpleTestFilter() { 31 public boolean include(String classpath) { 32 return super.include(classpath) && 33 SimpleTestFilter.getClassName(classpath).startsWith("SampleAPath"); 34 } 35 }; 36 builder.setFilter(filter); 37 38 Test suite = builder.suite(getFilename()); 39 assertNotNull(suite); 40 assertEquals(1, suite.countTestCases()); 41 } 42 43 49 public void testBuildSampleB() 50 throws Exception { 51 DirectorySuiteBuilder builder = new DirectorySuiteBuilder(); 52 TestFilter filter = new SimpleTestFilter() { 53 public boolean include(String classpath) { 54 return super.include(classpath) && 55 SimpleTestFilter.getClassName(classpath).startsWith("SampleBPath"); 56 } 57 }; 58 builder.setFilter(filter); 59 60 Test suite = builder.suite(getFilename()); 61 assertNotNull(suite); 62 assertEquals(2, suite.countTestCases()); 63 } 64 65 public void testBuildSample() 66 throws Exception { 67 DirectorySuiteBuilder builder = new DirectorySuiteBuilder(); 68 TestFilter filter = new SimpleTestFilter() { 69 public boolean include(String classpath) { 70 return super.include(classpath) && 71 SimpleTestFilter.getClassName(classpath).endsWith("PathTest"); 72 } 73 }; 74 builder.setFilter(filter); 75 76 Test suite = builder.suite(getFilename()); 77 assertNotNull(suite); 78 assertEquals(3, suite.countTestCases()); 79 } 80 81 public void testBrowse() 82 throws Exception { 83 DirectorySuiteBuilder builder = new DirectorySuiteBuilder(); 84 TestFilter filter = new SimpleTestFilter() { 85 public boolean include(String classpath) { 86 return super.include(classpath) && 87 SimpleTestFilter.getClassName(classpath).endsWith("PathTest"); 88 } 89 }; 90 builder.setFilter(filter); 91 92 List classes = builder.browse(new File (getFilename())); 93 94 assertEquals(2, classes.size()); 95 assertTrue(classes.contains("junitx.example.packageA.SampleAPathTest")); 96 assertTrue(classes.contains("junitx.example.packageA.packageB.SampleBPathTest")); 97 } 98 99 public void testIsTestClass() { 100 DirectorySuiteBuilder builder = new DirectorySuiteBuilder(); 101 TestFilter filter = new SimpleTestFilter() { 102 public boolean include(String classpath) { 103 return super.include(classpath) && 104 SimpleTestFilter.getClassName(classpath).endsWith("PathTest"); 105 } 106 }; 107 builder.setFilter(filter); 108 109 assertTrue(builder.isTestClass("/build/classes/junitx/example/packageA/SampleAPathTest.class")); 110 assertTrue(builder.isTestClass("/build/classes/junitx/example/packageA/packageB/SampleBPathTest.class")); 111 } 112 113 } 114 | Popular Tags |