Index: base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java |
diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java b/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java |
index 5f2b95e0f50165413709be41f6273d185f3b9d5a..97dde502a1b129490d87c7ae12bcce7886996a48 100644 |
--- a/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java |
+++ b/base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java |
@@ -7,6 +7,7 @@ package org.chromium.base.test.util; |
import junit.framework.TestCase; |
import org.chromium.base.Log; |
+import org.junit.runners.model.FrameworkMethod; |
import java.lang.annotation.Annotation; |
import java.lang.reflect.AnnotatedElement; |
@@ -23,16 +24,29 @@ public abstract class SkipCheck { |
/** |
* |
+ * Checks whether the given test method should be skipped. |
+ * |
+ * @param testMethod The test method to check. |
+ * @return Whether the test case should be skipped. |
+ */ |
+ public abstract boolean shouldSkip(FrameworkMethod testMethod); |
+ |
+ /** |
+ * |
* Checks whether the given test case should be skipped. |
* |
* @param testCase The test case to check. |
* @return Whether the test case should be skipped. |
*/ |
- public abstract boolean shouldSkip(TestCase testCase); |
+ public boolean shouldSkip(TestCase testCase) { |
+ FrameworkMethod frameworkMethod = getTestFrameworkMethod(testCase); |
+ return shouldSkip(frameworkMethod); |
+ } |
- protected static Method getTestMethod(TestCase testCase) { |
+ protected static FrameworkMethod getTestFrameworkMethod(TestCase testCase) { |
try { |
- return testCase.getClass().getMethod(testCase.getName(), (Class[]) null); |
+ Method m = testCase.getClass().getMethod(testCase.getName(), (Class[]) null); |
+ return new FrameworkMethod(m); |
} catch (NoSuchMethodException e) { |
Log.e(TAG, "Unable to find %s in %s", testCase.getName(), |
testCase.getClass().getName(), e); |
@@ -40,7 +54,11 @@ public abstract class SkipCheck { |
} |
} |
- @SuppressWarnings("unchecked") |
+ protected static <T extends Annotation> List<T> getAnnotations(FrameworkMethod frameworkMethod, |
+ Class<T> annotationClass) { |
+ return getAnnotations(frameworkMethod.getMethod(), annotationClass); |
+ } |
+ |
protected static <T extends Annotation> List<T> getAnnotations(AnnotatedElement element, |
Class<T> annotationClass) { |
AnnotatedElement parent = (element instanceof Method) |
@@ -49,12 +67,8 @@ public abstract class SkipCheck { |
List<T> annotations = (parent == null) |
? new ArrayList<T>() |
: getAnnotations(parent, annotationClass); |
- Annotation[] allAnnotations = element.getAnnotations(); |
- for (Annotation a : allAnnotations) { |
- if (annotationClass.isInstance(a)) { |
- annotations.add((T) a); |
- } |
- } |
+ T annotation = element.getAnnotation(annotationClass); |
+ if (annotation != null) annotations.add(annotation); |
return annotations; |
} |
} |