KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > framework > TestImplementorTest


1 package junit.tests.framework;
2
3 import junit.framework.*;
4
5 /**
6  * Test an implementor of junit.framework.Test other than TestCase or TestSuite
7  */

8 public class TestImplementorTest extends TestCase {
9     public static class DoubleTestCase implements Test {
10         private TestCase fTestCase;
11         
12         public DoubleTestCase(TestCase testCase) {
13             fTestCase= testCase;
14         }
15         
16         public int countTestCases() {
17             return 2;
18         }
19         
20         public void run(TestResult result) {
21             result.startTest(this);
22             Protectable p= new Protectable() {
23                 public void protect() throws Throwable JavaDoc {
24                     fTestCase.runBare();
25                     fTestCase.runBare();
26                 }
27             };
28             result.runProtected(this, p);
29             result.endTest(this);
30         }
31     }
32     
33     private DoubleTestCase fTest;
34     
35     public TestImplementorTest() {
36         TestCase testCase= new TestCase() {
37             public void runTest() {
38             }
39         };
40         fTest= new DoubleTestCase(testCase);
41     }
42     
43     public void testSuccessfulRun() {
44         TestResult result= new TestResult();
45         fTest.run(result);
46         assertEquals(fTest.countTestCases(), result.runCount());
47         assertEquals(0, result.errorCount());
48         assertEquals(0, result.failureCount());
49     }
50 }
51
Popular Tags