aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/runners/model/RunnerBuilder.java
diff options
context:
space:
mode:
authorPete Bentley <prb@google.com>2021-03-03 13:41:16 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-03 13:41:16 +0000
commitc7a6d4ec7defd99aab81c3add6e2916629a79a24 (patch)
tree9d0ef66d108d76d38341cb002d5a46f74299983f /src/main/java/org/junit/runners/model/RunnerBuilder.java
parent91c5e5ff9d71ebc00818b310c09b175016c36dc2 (diff)
parentfcd81b3e3fa66cb13ab508ef8f9a4a8704309350 (diff)
downloadjunit-c7a6d4ec7defd99aab81c3add6e2916629a79a24.tar.gz
Merge changes I578a2676,I4b37c2d0,Id1e2d638,I1ebe37da,I6135799c am: b6446bec0a am: fcd81b3e3f
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1613132 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ide8f718358c2b88fb4af0b2b2792f5a560de4d67
Diffstat (limited to 'src/main/java/org/junit/runners/model/RunnerBuilder.java')
-rw-r--r--src/main/java/org/junit/runners/model/RunnerBuilder.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/main/java/org/junit/runners/model/RunnerBuilder.java b/src/main/java/org/junit/runners/model/RunnerBuilder.java
index 7d3eee3..ba7c9e2 100644
--- a/src/main/java/org/junit/runners/model/RunnerBuilder.java
+++ b/src/main/java/org/junit/runners/model/RunnerBuilder.java
@@ -6,7 +6,11 @@ import java.util.List;
import java.util.Set;
import org.junit.internal.runners.ErrorReportingRunner;
+import org.junit.runner.Description;
+import org.junit.runner.OrderWith;
import org.junit.runner.Runner;
+import org.junit.runner.manipulation.InvalidOrderingException;
+import org.junit.runner.manipulation.Ordering;
/**
* A RunnerBuilder is a strategy for constructing runners for classes.
@@ -49,19 +53,39 @@ public abstract class RunnerBuilder {
public abstract Runner runnerForClass(Class<?> testClass) throws Throwable;
/**
- * Always returns a runner, even if it is just one that prints an error instead of running tests.
+ * Always returns a runner for the given test class.
+ *
+ * <p>In case of an exception a runner will be returned that prints an error instead of running
+ * tests.
+ *
+ * <p>Note that some of the internal JUnit implementations of RunnerBuilder will return
+ * {@code null} from this method, but no RunnerBuilder passed to a Runner constructor will
+ * return {@code null} from this method.
*
* @param testClass class to be run
* @return a Runner
*/
public Runner safeRunnerForClass(Class<?> testClass) {
try {
- return runnerForClass(testClass);
+ Runner runner = runnerForClass(testClass);
+ if (runner != null) {
+ configureRunner(runner);
+ }
+ return runner;
} catch (Throwable e) {
return new ErrorReportingRunner(testClass, e);
}
}
+ private void configureRunner(Runner runner) throws InvalidOrderingException {
+ Description description = runner.getDescription();
+ OrderWith orderWith = description.getAnnotation(OrderWith.class);
+ if (orderWith != null) {
+ Ordering ordering = Ordering.definedBy(orderWith.value(), description);
+ ordering.apply(runner);
+ }
+ }
+
Class<?> addParent(Class<?> parent) throws InitializationError {
if (!parents.add(parent)) {
throw new InitializationError(String.format("class '%s' (possibly indirectly) contains itself as a SuiteClass", parent.getName()));
@@ -96,7 +120,7 @@ public abstract class RunnerBuilder {
}
private List<Runner> runners(Class<?>[] children) {
- ArrayList<Runner> runners = new ArrayList<Runner>();
+ List<Runner> runners = new ArrayList<Runner>();
for (Class<?> each : children) {
Runner childRunner = safeRunnerForClass(each);
if (childRunner != null) {