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

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

Issue 1761383002: [Android] Restrict tests inheriting from DocumentModeTestBase to phones. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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 Annotation[] allAnnotations = element.getAnnotations();
52 for (Annotation a : allAnnotations) {
53 if (annotationClass.isInstance(a)) {
54 annotations.add((T) a);
55 }
56 }
57 return annotations;
58 }
38 } 59 }
39 60
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698