Skip to content

Commit

Permalink
Introduce MemoizingRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
kcooney committed Jun 2, 2018
1 parent 550654a commit 74b914f
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/main/java/org/junit/internal/requests/ClassRequest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package org.junit.internal.requests;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
import org.junit.internal.builders.SuiteMethodBuilder;
import org.junit.runner.Request;
import org.junit.runner.Runner;
import org.junit.runners.model.RunnerBuilder;

public class ClassRequest extends Request {
private final Lock runnerLock = new ReentrantLock();

public class ClassRequest extends MemoizingRequest {
/*
* We have to use the f prefix, because IntelliJ's JUnit4IdeaTestRunner uses
* reflection to access this field. See
* https://github.com/junit-team/junit4/issues/960
*/
private final Class<?> fTestClass;
private final boolean canUseSuiteMethod;
private volatile Runner runner;

public ClassRequest(Class<?> testClass, boolean canUseSuiteMethod) {
this.fTestClass = testClass;
Expand All @@ -31,18 +24,8 @@ public ClassRequest(Class<?> testClass) {
}

@Override
public Runner getRunner() {
if (runner == null) {
runnerLock.lock();
try {
if (runner == null) {
runner = new CustomAllDefaultPossibilitiesBuilder().safeRunnerForClass(fTestClass);
}
} finally {
runnerLock.unlock();
}
}
return runner;
protected Runner createRunner() {
return new CustomAllDefaultPossibilitiesBuilder().safeRunnerForClass(fTestClass);
}

private class CustomAllDefaultPossibilitiesBuilder extends AllDefaultPossibilitiesBuilder {
Expand Down

0 comments on commit 74b914f

Please sign in to comment.