1b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpackage junit.framework; 2b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 3b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport java.util.List; 4b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 5b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.Ignore; 6b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.Describable; 7b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.Description; 8b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.Request; 9b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.Runner; 10b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.manipulation.Filter; 11b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.manipulation.Filterable; 12b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.manipulation.NoTestsRemainException; 13b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.manipulation.Sortable; 14b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotimport org.junit.runner.manipulation.Sorter; 15b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 16b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabotpublic class JUnit4TestAdapter implements Test, Filterable, Sortable, Describable { 17b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot private final Class<?> fNewTestClass; 18b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 19b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot private final Runner fRunner; 20b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 21b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot private final JUnit4TestAdapterCache fCache; 22b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 23b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public JUnit4TestAdapter(Class<?> newTestClass) { 24b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot this(newTestClass, JUnit4TestAdapterCache.getDefault()); 25b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 26b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 27b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public JUnit4TestAdapter(final Class<?> newTestClass, 28b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot JUnit4TestAdapterCache cache) { 29b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot fCache = cache; 30b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot fNewTestClass = newTestClass; 31b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); 32b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 33b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 34b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public int countTestCases() { 35b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return fRunner.testCount(); 36b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 37b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 38b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public void run(TestResult result) { 39b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot fRunner.run(fCache.getNotifier(result, this)); 40b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 41b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 42b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot // reflective interface for Eclipse 43b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public List<Test> getTests() { 44b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return fCache.asTestList(getDescription()); 45b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 46b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 47b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot // reflective interface for Eclipse 48b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public Class<?> getTestClass() { 49b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return fNewTestClass; 50b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 51b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 52b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public Description getDescription() { 53b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot Description description= fRunner.getDescription(); 54b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return removeIgnored(description); 55b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 56b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 57b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot private Description removeIgnored(Description description) { 58b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot if (isIgnored(description)) 59b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return Description.EMPTY; 60b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot Description result = description.childlessCopy(); 61b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot for (Description each : description.getChildren()) { 62b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot Description child= removeIgnored(each); 63b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot if (! child.isEmpty()) 64b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot result.addChild(child); 65b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 66b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return result; 67b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 68b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 69b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot private boolean isIgnored(Description description) { 70b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return description.getAnnotation(Ignore.class) != null; 71b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 72b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 73b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot @Override 74b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public String toString() { 75b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot return fNewTestClass.getName(); 76b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 77b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 78b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public void filter(Filter filter) throws NoTestsRemainException { 79b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot filter.apply(fRunner); 80b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 81b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot 82b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot public void sort(Sorter sorter) { 83b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot sorter.apply(fRunner); 84b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot } 85b3823db9f1192d8c81345740b3e65bd6738ba55bBrett Chabot}