Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/util/SkipCheck.java

Issue 2273553002: Create BaseJUnitClassRunner to run junit4 style tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not obfuscate junit Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..33dea8346a21e9856a590a5641df9bb50d534a17 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
@@ -6,6 +6,8 @@ package org.chromium.base.test.util;
import junit.framework.TestCase;
+import org.junit.runners.model.FrameworkMethod;
+
import org.chromium.base.Log;
import java.lang.annotation.Annotation;
@@ -23,24 +25,36 @@ 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);
-
- protected static Method getTestMethod(TestCase testCase) {
+ public boolean shouldSkip(TestCase testCase) {
try {
- return testCase.getClass().getMethod(testCase.getName(), (Class[]) null);
+ Method m = testCase.getClass().getMethod(testCase.getName(), (Class[]) null);
+ return shouldSkip(new FrameworkMethod(m));
} catch (NoSuchMethodException e) {
Log.e(TAG, "Unable to find %s in %s", testCase.getName(),
testCase.getClass().getName(), e);
- return null;
+ return false;
}
}
- @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 +63,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;
}
}

Powered by Google App Engine
This is Rietveld 408576698