1 package junit.framework; 2 3 import java.util.List ; 4 5 import org.junit.runner.Description; 6 import org.junit.runner.Request; 7 import org.junit.runner.Runner; 8 9 public class JUnit4TestAdapter implements Test { 10 private final Class <?> fNewTestClass; 11 12 private Runner fRunner; 13 14 private JUnit4TestAdapterCache fCache; 15 16 public JUnit4TestAdapter(Class <?> newTestClass) { 17 this(newTestClass, JUnit4TestAdapterCache.getDefault()); 18 } 19 20 public JUnit4TestAdapter(final Class <?> newTestClass, 21 JUnit4TestAdapterCache cache) { 22 fCache = cache; 23 fNewTestClass = newTestClass; 24 fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); 25 } 26 27 public int countTestCases() { 28 return fRunner.testCount(); 29 } 30 31 public void run(TestResult result) { 32 fRunner.run(fCache.getNotifier(result, this)); 33 } 34 35 public List <Test> getTests() { 37 return fCache.asTestList(getDescription()); 38 } 39 40 public Class <?> getTestClass() { 42 return fNewTestClass; 43 } 44 45 public Description getDescription() { 46 return fRunner.getDescription(); 47 } 48 49 @Override 50 public String toString() { 51 return fNewTestClass.getName(); 52 } 53 } | Popular Tags |