KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > framework > JUnit4TestAdapter


1 package junit.framework;
2
3 import java.util.List JavaDoc;
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 JavaDoc<?> fNewTestClass;
11
12     private Runner fRunner;
13
14     private JUnit4TestAdapterCache fCache;
15
16     public JUnit4TestAdapter(Class JavaDoc<?> newTestClass) {
17         this(newTestClass, JUnit4TestAdapterCache.getDefault());
18     }
19
20     public JUnit4TestAdapter(final Class JavaDoc<?> 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     // reflective interface for Eclipse
36
public List JavaDoc<Test> getTests() {
37         return fCache.asTestList(getDescription());
38     }
39
40     // reflective interface for Eclipse
41
public Class JavaDoc<?> getTestClass() {
42         return fNewTestClass;
43     }
44     
45     public Description getDescription() {
46         return fRunner.getDescription();
47     }
48
49     @Override JavaDoc
50     public String JavaDoc toString() {
51         return fNewTestClass.getName();
52     }
53 }
Popular Tags