Index: base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java |
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java |
index aaa5c660865e46763aec79664cd292de09b5ca5e..850cea4230c1e3a950fdde153cd01189d6070c06 100644 |
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java |
+++ b/base/test/android/javatests/src/org/chromium/base/test/BaseJUnit4ClassRunner.java |
@@ -4,7 +4,6 @@ |
package org.chromium.base.test; |
-import android.content.Context; |
import android.support.test.InstrumentationRegistry; |
import org.junit.runner.notification.RunNotifier; |
@@ -12,13 +11,11 @@ import org.junit.runners.BlockJUnit4ClassRunner; |
import org.junit.runners.model.FrameworkMethod; |
import org.junit.runners.model.InitializationError; |
-import org.chromium.base.test.BaseTestResult.PreTestHook; |
import org.chromium.base.test.util.DisableIfSkipCheck; |
import org.chromium.base.test.util.MinAndroidSdkLevelSkipCheck; |
import org.chromium.base.test.util.RestrictionSkipCheck; |
import org.chromium.base.test.util.SkipCheck; |
-import java.lang.reflect.Method; |
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.List; |
@@ -28,7 +25,6 @@ import java.util.List; |
*/ |
public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
private final List<SkipCheck> mSkipChecks; |
- private final List<PreTestHook> mPreTestHooks; |
/** |
* Create a BaseJUnit4ClassRunner to run {@code klass} and initialize values |
@@ -36,16 +32,16 @@ public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
* @throws InitializationError if the test class malformed |
*/ |
public BaseJUnit4ClassRunner(final Class<?> klass) throws InitializationError { |
- this(klass, null, null); |
+ this(klass, null); |
} |
/** |
* Create a BaseJUnit4ClassRunner to run {@code klass} and initialize values. |
* |
- * To add more SkipCheck or PreTestHook in subclass, create Lists of checks and hooks, |
- * pass them into the super constructors. If you want make a subclass extendable by other |
- * class runners, you also have to create a constructor similar to the following one that |
- * merges default checks or hooks with this checks and hooks passed in by constructor. |
+ * To add more SkipCheck in subclass, create Lists of checks, pass them into the super |
+ * constructors. If you want make a subclass extendable by other class runners, you also have |
+ * to create a constructor similar to the following one that merges default checks with these |
+ * checks passed in by constructor. |
* |
* <pre> |
* <code> |
@@ -53,40 +49,36 @@ public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
* public ChildRunner extends BaseJUnit4ClassRunner { |
* public ChildRunner(final Class<?> klass) { |
* throws InitializationError { |
- * this(klass, null, null); |
+ * this(klass, null); |
* } |
* |
* public ChildRunner( |
- * final Class<?> klass, List<SkipCheck> checks, List<PreTestHook> hook) { |
+ * final Class<?> klass, List<SkipCheck> checks) { |
* throws InitializationError { |
- * super(klass, mergeList( |
- * checks, defaultSkipChecks()), mergeList(hooks, DEFAULT_HOOKS)); |
+ * super(klass, mergeSkipChecks(checks, defaultSkipChecks())); |
* } |
* |
* public List<SkipCheck> defaultSkipChecks() {...} |
- * |
- * public List<PreTestHook> defaultPreTestHooks() {...} |
* </code> |
* </pre> |
* |
* @throws InitializationError if the test class malformed |
*/ |
- public BaseJUnit4ClassRunner( |
- final Class<?> klass, List<SkipCheck> checks, List<PreTestHook> hooks) |
+ public BaseJUnit4ClassRunner(final Class<?> klass, List<SkipCheck> childSkipChecks) |
throws InitializationError { |
super(klass); |
- mSkipChecks = mergeList(checks, defaultSkipChecks()); |
- mPreTestHooks = defaultPreTestHooks(); |
+ mSkipChecks = mergeSkipChecks(childSkipChecks, defaultSkipChecks()); |
} |
/** |
* Merge two List into a new ArrayList. |
* |
* Used to merge the default SkipChecks/PreTestHooks with the subclasses's |
- * SkipChecks/PreTestHooks. |
+ * SkipChecks. |
*/ |
- protected static final <T> List<T> mergeList(List<T> listA, List<T> listB) { |
- List<T> l = new ArrayList<>(); |
+ protected static final List<SkipCheck> mergeSkipChecks( |
+ List<SkipCheck> listA, List<SkipCheck> listB) { |
+ List<SkipCheck> l = new ArrayList<>(); |
if (listA != null) { |
l.addAll(listA); |
} |
@@ -99,7 +91,7 @@ public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
/** |
* Change this static function to add or take out default {@code SkipCheck}s. |
*/ |
- private static List<SkipCheck> defaultSkipChecks() { |
+ protected static List<SkipCheck> defaultSkipChecks() { |
return Arrays.asList(new SkipCheck[]{ |
new RestrictionSkipCheck(InstrumentationRegistry.getTargetContext()), |
new MinAndroidSdkLevelSkipCheck(), |
@@ -108,13 +100,6 @@ public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
} |
/** |
- * Change this static function to add or take out default {@code PreTestHook}s. |
- */ |
- private static List<PreTestHook> defaultPreTestHooks() { |
- return new ArrayList<PreTestHook>(); |
- } |
- |
- /** |
* Evaluate whether a FrameworkMethod is ignored based on {@code SkipCheck}s. |
*/ |
@Override |
@@ -124,22 +109,10 @@ public class BaseJUnit4ClassRunner extends BlockJUnit4ClassRunner { |
@Override |
protected void runChild(FrameworkMethod method, RunNotifier notifier) { |
- runPreTestHooks(method); |
super.runChild(method, notifier); |
} |
/** |
- * Loop through all the {@code PreTestHook}s to run them |
- */ |
- private void runPreTestHooks(FrameworkMethod frameworkMethod) { |
- Method testMethod = frameworkMethod.getMethod(); |
- Context targetContext = InstrumentationRegistry.getTargetContext(); |
- for (PreTestHook hook : mPreTestHooks) { |
- hook.run(targetContext, testMethod); |
- } |
- } |
- |
- /** |
* Loop through all the {@code SkipCheck}s to confirm whether a test should be ignored |
*/ |
private boolean shouldSkip(FrameworkMethod method) { |