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

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java

Issue 2722243002: 📰 Add tests for Tile and TileGroup (Closed)
Patch Set: moar tests Created 3 years, 10 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: testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java b/testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java
index 86ac990c300d6ed5738c6728d48a38fca71b1a37..8bfc04d42f581a5d57906cb5724828263bf13559 100644
--- a/testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java
+++ b/testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java
@@ -37,21 +37,30 @@
*/
public abstract class AnnotationProcessor<T extends Annotation> extends ExternalResource {
private final Class<T> mAnnotationClass;
+ private final boolean mAlwaysApply;
private Description mTestDescription;
private T mAnnotation;
- public AnnotationProcessor(Class<T> annotationClass) {
+ /**
+ * @param annotationClass The annotation to detect to trigger to rule.
+ * @param alwaysApply Whether the rule should trigger even when the annotation is not found.
+ */
+ public AnnotationProcessor(Class<T> annotationClass, boolean alwaysApply) {
Bernhard Bauer 2017/03/03 11:54:39 I find it a bit strange to have AnnotationProcesso
dgn 2017/03/03 13:48:30 Currently just adding @EnableFeatures at the class
mAnnotationClass = annotationClass;
+ mAlwaysApply = alwaysApply;
}
@Override
public Statement apply(Statement base, Description description) {
mTestDescription = description;
mAnnotation = description.getAnnotation(mAnnotationClass);
Bernhard Bauer 2017/03/03 11:54:38 Maybe extract getting the annotation into a helper
dgn 2017/03/03 13:48:30 Done.
- if (mAnnotation == null) return base;
+ if (mAnnotation != null) return super.apply(base, description);
- // Return the wrapped statement to execute before() and after().
- return super.apply(base, description);
+ mAnnotation = description.getTestClass().getAnnotation(mAnnotationClass);
+ if (mAnnotation != null) return super.apply(base, description);
+
+ // No annotation, return the plain statement without executing before() and after().
+ return mAlwaysApply ? super.apply(base, description) : base;
}
/** @return {@link Description} of the current test. */

Powered by Google App Engine
This is Rietveld 408576698