diff options
author | Brett Chabot <brettchabot@android.com> | 2013-04-01 16:00:16 -0700 |
---|---|---|
committer | Brett Chabot <brettchabot@android.com> | 2013-04-01 16:02:29 -0700 |
commit | b0d7f03bf4113d56c4b96aac94e6b30ff8f9a2b5 (patch) | |
tree | df32844dad505bc94910d0475c307184c146a7d3 /src | |
parent | 1e4a5275f1f19aac72d395c1fe995bab1be54361 (diff) | |
download | junit-b0d7f03bf4113d56c4b96aac94e6b30ff8f9a2b5.tar.gz |
Collect annotations for JUnit3 tests.
Necessary to support test annotation filtering in Android.
Change-Id: Id4c2923bf3f0aff0847dc8b4705a502c7540d80d
Diffstat (limited to 'src')
-rw-r--r-- | src/org/junit/internal/runners/JUnit38ClassRunner.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/org/junit/internal/runners/JUnit38ClassRunner.java b/src/org/junit/internal/runners/JUnit38ClassRunner.java index 98c5773..acb18f8 100644 --- a/src/org/junit/internal/runners/JUnit38ClassRunner.java +++ b/src/org/junit/internal/runners/JUnit38ClassRunner.java @@ -7,6 +7,7 @@ import junit.framework.TestCase; import junit.framework.TestListener; import junit.framework.TestResult; import junit.framework.TestSuite; + import org.junit.runner.Describable; import org.junit.runner.Description; import org.junit.runner.Runner; @@ -18,6 +19,10 @@ import org.junit.runner.manipulation.Sorter; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + public class JUnit38ClassRunner extends Runner implements Filterable, Sortable { private final class OldTestClassAdaptingListener implements TestListener { @@ -95,7 +100,9 @@ public class JUnit38ClassRunner extends Runner implements Filterable, Sortable { private static Description makeDescription(Test test) { if (test instanceof TestCase) { TestCase tc= (TestCase) test; - return Description.createTestDescription(tc.getClass(), tc.getName()); + // android-changed - add getAnnotations(test) call + return Description.createTestDescription(tc.getClass(), tc.getName(), + getAnnotations(tc)); } else if (test instanceof TestSuite) { TestSuite ts= (TestSuite) test; String name= ts.getName() == null ? createSuiteDescription(ts) : ts.getName(); @@ -118,6 +125,25 @@ public class JUnit38ClassRunner extends Runner implements Filterable, Sortable { } } + // android-changed added to support annotation filtering + /** + * Get the annotations associated with given TestCase. + * @param test + * @return + */ + private static Annotation[] getAnnotations(TestCase test) { + try { + Method m = test.getClass().getDeclaredMethod(test.getName()); + return m.getDeclaredAnnotations(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + return new Annotation[0]; + } + // android-changed end + private static String createSuiteDescription(TestSuite ts) { int count= ts.countTestCases(); String example = count == 0 ? "" : String.format(" [example: %s]", ts.testAt(0)); @@ -162,6 +188,6 @@ public class JUnit38ClassRunner extends Runner implements Filterable, Sortable { * Creates a shallow copy of given {@link TestSuite}. */ protected TestSuite createCopyOfSuite(TestSuite suite) { - return new TestSuite(suite.getName()); + return new TestSuite(suite.getName()); } } |