OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.testing.local; | 5 package org.chromium.testing.local; |
6 | 6 |
7 import org.junit.rules.ExternalResource; | 7 import org.junit.rules.ExternalResource; |
8 import org.junit.runner.Description; | 8 import org.junit.runner.Description; |
9 import org.junit.runners.model.Statement; | 9 import org.junit.runners.model.Statement; |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 private Description mTestDescription; | 40 private Description mTestDescription; |
41 private T mAnnotation; | 41 private T mAnnotation; |
42 | 42 |
43 public AnnotationProcessor(Class<T> annotationClass) { | 43 public AnnotationProcessor(Class<T> annotationClass) { |
44 mAnnotationClass = annotationClass; | 44 mAnnotationClass = annotationClass; |
45 } | 45 } |
46 | 46 |
47 @Override | 47 @Override |
48 public Statement apply(Statement base, Description description) { | 48 public Statement apply(Statement base, Description description) { |
49 mTestDescription = description; | 49 mTestDescription = description; |
50 mAnnotation = description.getAnnotation(mAnnotationClass); | 50 mAnnotation = getAnnotation(description); |
51 if (mAnnotation == null) return base; | 51 if (mAnnotation == null) return base; |
52 | 52 |
53 // Return the wrapped statement to execute before() and after(). | 53 // Return the wrapped statement to execute before() and after(). |
54 return super.apply(base, description); | 54 return super.apply(base, description); |
55 } | 55 } |
56 | 56 |
57 /** @return {@link Description} of the current test. */ | 57 /** @return {@link Description} of the current test. */ |
58 protected Description getTestDescription() { | 58 protected Description getTestDescription() { |
59 return mTestDescription; | 59 return mTestDescription; |
60 } | 60 } |
61 | 61 |
62 /** @return the annotation that caused the test to be processed. */ | 62 /** @return the annotation that caused the test to be processed. */ |
63 protected T getAnnotation() { | 63 protected T getAnnotation() { |
64 return mAnnotation; | 64 return mAnnotation; |
65 } | 65 } |
| 66 |
| 67 private T getAnnotation(Description description) { |
| 68 T annotation = description.getAnnotation(mAnnotationClass); |
| 69 if (annotation != null) return annotation; |
| 70 |
| 71 annotation = description.getTestClass().getAnnotation(mAnnotationClass); |
| 72 return annotation; |
| 73 } |
66 } | 74 } |
OLD | NEW |