OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.base.test.util; | 5 package org.chromium.base.test.util; |
6 | 6 |
7 import junit.framework.TestCase; | 7 import junit.framework.TestCase; |
8 | 8 |
9 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
10 | 10 |
11 import java.lang.annotation.Annotation; | |
12 import java.lang.reflect.AnnotatedElement; | |
11 import java.lang.reflect.Method; | 13 import java.lang.reflect.Method; |
14 import java.util.ArrayList; | |
15 import java.util.List; | |
12 | 16 |
13 /** | 17 /** |
14 * Check whether a test case should be skipped. | 18 * Check whether a test case should be skipped. |
15 */ | 19 */ |
16 public abstract class SkipCheck { | 20 public abstract class SkipCheck { |
17 | 21 |
18 private static final String TAG = "base_test"; | 22 private static final String TAG = "base_test"; |
19 | 23 |
20 /** | 24 /** |
21 * | 25 * |
22 * Checks whether the given test case should be skipped. | 26 * Checks whether the given test case should be skipped. |
23 * | 27 * |
24 * @param testCase The test case to check. | 28 * @param testCase The test case to check. |
25 * @return Whether the test case should be skipped. | 29 * @return Whether the test case should be skipped. |
26 */ | 30 */ |
27 public abstract boolean shouldSkip(TestCase testCase); | 31 public abstract boolean shouldSkip(TestCase testCase); |
28 | 32 |
29 protected static Method getTestMethod(TestCase testCase) { | 33 protected static Method getTestMethod(TestCase testCase) { |
30 try { | 34 try { |
31 return testCase.getClass().getMethod(testCase.getName(), (Class[]) n ull); | 35 return testCase.getClass().getMethod(testCase.getName(), (Class[]) n ull); |
32 } catch (NoSuchMethodException e) { | 36 } catch (NoSuchMethodException e) { |
33 Log.e(TAG, "Unable to find %s in %s", testCase.getName(), | 37 Log.e(TAG, "Unable to find %s in %s", testCase.getName(), |
34 testCase.getClass().getName(), e); | 38 testCase.getClass().getName(), e); |
35 return null; | 39 return null; |
36 } | 40 } |
37 } | 41 } |
42 | |
43 protected static <T extends Annotation> List<T> getAnnotations(AnnotatedElem ent element, | |
44 Class<T> annotationClass) { | |
45 AnnotatedElement parent = (element instanceof Method) | |
46 ? ((Method) element).getDeclaringClass() | |
47 : ((Class) element).getSuperclass(); | |
48 List<T> annotations = (parent == null) | |
49 ? new ArrayList<T>() | |
50 : getAnnotations(parent, annotationClass); | |
51 T val = element.getAnnotation(annotationClass); | |
52 if (val != null) annotations.add(val); | |
newt (away)
2016/03/07 18:07:09
How does this work if there are multiple restricti
jbudorick
2016/03/08 00:18:55
This works with MultipleRestrictionsRestrictedClas
| |
53 return annotations; | |
54 } | |
38 } | 55 } |
39 | 56 |
OLD | NEW |