View Javadoc
1   package junit.tests.framework;
2   
3   import junit.framework.Protectable;
4   import junit.framework.Test;
5   import junit.framework.TestCase;
6   import junit.framework.TestResult;
7   
8   /**
9    * Test an implementor of junit.framework.Test other than TestCase or TestSuite
10   */
11  public class TestImplementorTest extends TestCase {
12      public static class DoubleTestCase implements Test {
13          private TestCase fTestCase;
14  
15          public DoubleTestCase(TestCase testCase) {
16              fTestCase = testCase;
17          }
18  
19          public int countTestCases() {
20              return 2;
21          }
22  
23          public void run(TestResult result) {
24              result.startTest(this);
25              Protectable p = new Protectable() {
26                  public void protect() throws Throwable {
27                      fTestCase.runBare();
28                      fTestCase.runBare();
29                  }
30              };
31              result.runProtected(this, p);
32              result.endTest(this);
33          }
34      }
35  
36      private DoubleTestCase fTest;
37  
38      public TestImplementorTest() {
39          TestCase testCase = new TestCase() {
40              @Override
41              public void runTest() {
42              }
43          };
44          fTest = new DoubleTestCase(testCase);
45      }
46  
47      public void testSuccessfulRun() {
48          TestResult result = new TestResult();
49          fTest.run(result);
50          assertEquals(fTest.countTestCases(), result.runCount());
51          assertEquals(0, result.errorCount());
52          assertEquals(0, result.failureCount());
53      }
54  }