Permalink
Browse files

Merge pull request #412 from kcooney/class-request-memoize-runner

Make ClassRequest memoize the runner.
  • Loading branch information...
2 parents 7b47d56 + 4154013 commit 34d2943cef583ecb34cc182b79dbb4af0c778b3f @dsaff dsaff committed Apr 12, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/main/java/org/junit/internal/requests/ClassRequest.java
@@ -6,9 +6,10 @@
import org.junit.runner.Runner;
public class ClassRequest extends Request {
+ private final Object fRunnerLock = new Object();
private final Class<?> fTestClass;
-
- private boolean fCanUseSuiteMethod;
+ private final boolean fCanUseSuiteMethod;
+ private Runner fRunner;
public ClassRequest(Class<?> testClass, boolean canUseSuiteMethod) {
fTestClass= testClass;
@@ -21,6 +22,11 @@ public ClassRequest(Class<?> testClass) {
@Override
public Runner getRunner() {
- return new AllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass);
+ synchronized (fRunnerLock) {
+ if (fRunner == null) {
+ fRunner = new AllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass);
+ }
+ return fRunner;
+ }
}
}

0 comments on commit 34d2943

Please sign in to comment.