KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > util > DirectorySuiteBuilderTest


1 package junitx.util;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5
6 import java.io.File JavaDoc;
7 import java.util.List JavaDoc;
8
9 /**
10  * @version $Revision: 1.6 $ $Date: 2003/04/02 04:50:43 $
11  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
12  */

13 public class DirectorySuiteBuilderTest
14         extends TestCase {
15
16     public DirectorySuiteBuilderTest(String JavaDoc name) {
17         super(name);
18     }
19
20     public String JavaDoc getFilename() {
21         return "build/classes-example";
22     }
23     
24     /**
25      * The Sample1Test class contains 1 method and no suite() method.
26      */

27     public void testBuildSampleA()
28             throws Exception JavaDoc {
29         DirectorySuiteBuilder builder = new DirectorySuiteBuilder();
30         TestFilter filter = new SimpleTestFilter() {
31             public boolean include(String JavaDoc 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     /**
44      * The Sample2Test class contains 3 test methods but its suite()
45      * method only takes the first 2 into account. The build suite
46      * must contain 2 tests since the suite method has priority
47      * vs. the reflection mechanism.
48      */

49     public void testBuildSampleB()
50             throws Exception JavaDoc {
51         DirectorySuiteBuilder builder = new DirectorySuiteBuilder();
52         TestFilter filter = new SimpleTestFilter() {
53             public boolean include(String JavaDoc 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 JavaDoc {
67         DirectorySuiteBuilder builder = new DirectorySuiteBuilder();
68         TestFilter filter = new SimpleTestFilter() {
69             public boolean include(String JavaDoc 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 JavaDoc {
83         DirectorySuiteBuilder builder = new DirectorySuiteBuilder();
84         TestFilter filter = new SimpleTestFilter() {
85             public boolean include(String JavaDoc classpath) {
86                 return super.include(classpath) &&
87                     SimpleTestFilter.getClassName(classpath).endsWith("PathTest");
88             }
89         };
90         builder.setFilter(filter);
91
92         List JavaDoc classes = builder.browse(new File JavaDoc(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 JavaDoc 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