KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > util > AbstractArchiveSuiteBuilderTest


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

12 public abstract class AbstractArchiveSuiteBuilderTest extends TestCase {
13
14     protected ZipFile JavaDoc file;
15
16     public AbstractArchiveSuiteBuilderTest(String JavaDoc name) {
17         super(name);
18     }
19
20     public void setUp() throws Exception JavaDoc {
21         this.file = new ZipFile JavaDoc(getFilename());
22     }
23
24     public void tearDown() throws Exception JavaDoc {
25         this.file.close();
26     }
27
28     abstract protected String JavaDoc getFilename();
29
30     /**
31      * The Sample1Test class contains 1 method and no suite() method.
32      */

33     public void testBuildSampleA() throws Exception JavaDoc {
34         ArchiveSuiteBuilder builder = new ArchiveSuiteBuilder();
35         TestFilter filter = new SimpleTestFilter() {
36             public boolean include(String JavaDoc classpath) {
37                 return super.include(classpath) &&
38                     SimpleTestFilter.getClassName(classpath).startsWith("SampleA");
39             }
40         };
41         builder.setFilter(filter);
42
43         Test suite = builder.suite(getFilename());
44         assertNotNull(suite);
45         assertEquals(1, suite.countTestCases());
46     }
47
48     /**
49      * The Sample2Test class contains 3 test methods but its suite()
50      * method only takes the first 2 into account. The build suite
51      * must contain 2 tests since the suite method has priority
52      * vs. the reflection mechanism.
53      */

54     public void testBuildSampleB() throws Exception JavaDoc {
55         ArchiveSuiteBuilder builder = new ArchiveSuiteBuilder();
56         TestFilter filter = new SimpleTestFilter() {
57             public boolean include(String JavaDoc classpath) {
58                 return super.include(classpath) &&
59                     SimpleTestFilter.getClassName(classpath).startsWith("SampleB");
60             }
61         };
62         builder.setFilter(filter);
63
64         Test suite = builder.suite(getFilename());
65         assertNotNull(suite);
66         assertEquals(2, suite.countTestCases());
67     }
68
69     public void testBuildSamples() throws Exception JavaDoc {
70         ArchiveSuiteBuilder builder = new ArchiveSuiteBuilder();
71
72         Test suite = builder.suite(getFilename());
73         assertNotNull(suite);
74         assertEquals(3, suite.countTestCases());
75     }
76
77 }
78
Popular Tags