Source of TestImplementorTest.java


  1: package junit.tests.framework;

  3: import junit.framework.*;

  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 {
 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: }