Chromium Code Reviews| 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. */ |