Don't load the class before evaluation of a subrule, invoke lazily.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1298925 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-03-09 16:58:01 +00:00
parent 9c61a0e8ce
commit 09d422f14f
1 changed files with 6 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class StoreClassNameRule implements TestRule {
private volatile Class<?> testClass;
private volatile Description description;
@Override
public Statement apply(final Statement s, final Description d) {
@ -17,10 +17,10 @@ public class StoreClassNameRule implements TestRule {
@Override
public void evaluate() throws Throwable {
try {
testClass = d.getTestClass();
description = d;
s.evaluate();
} finally {
testClass = null;
description = null;
}
}
};
@ -30,10 +30,10 @@ public class StoreClassNameRule implements TestRule {
* Returns the test class currently executing in this rule.
*/
public Class<?> getTestClass() {
Class<?> clz = testClass;
if (clz == null) {
Description localDescription = description;
if (localDescription == null) {
throw new RuntimeException("The rule is not currently executing.");
}
return clz;
return localDescription.getTestClass();
}
}