[SPR-4643] SpringJUnit4ClassRunner now optionally calls JUnit 4.7's BlockJUnit4ClassRunner.withRules() method using reflection in order to provide backward compatibility with JUnit 4.5 and 4.6.

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1835 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Sam Brannen
2009-09-07 21:03:32 +00:00
parent 75e4b86c95
commit aca7cf4c58
3 changed files with 75 additions and 2 deletions
@@ -45,6 +45,7 @@ import org.springframework.test.context.junit4.statements.RunBeforeTestClassCall
import org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks;
import org.springframework.test.context.junit4.statements.SpringFailOnTimeout;
import org.springframework.test.context.junit4.statements.SpringRepeat;
import org.springframework.util.ReflectionUtils;
/**
* <p>
@@ -307,6 +308,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
Statement statement = methodInvoker(frameworkMethod, testInstance);
statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
statement = withRulesReflectively(frameworkMethod, testInstance, statement);
statement = withBefores(frameworkMethod, testInstance, statement);
statement = withAfters(frameworkMethod, testInstance, statement);
statement = withPotentialRepeat(frameworkMethod, testInstance, statement);
@@ -315,6 +317,24 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
return statement;
}
/**
* Invokes JUnit 4.7's private <code>withRules()</code> method using
* reflection. This is necessary for backwards compatibility with the JUnit
* 4.5 and 4.6 implementations of {@link BlockJUnit4ClassRunner}.
*/
private Statement withRulesReflectively(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
Method withRulesMethod = ReflectionUtils.findMethod(getClass(), "withRules", FrameworkMethod.class,
Object.class, Statement.class);
if (withRulesMethod != null) {
// Original JUnit 4.7 code:
// statement = withRules(frameworkMethod, testInstance, statement);
ReflectionUtils.makeAccessible(withRulesMethod);
statement = (Statement) ReflectionUtils.invokeMethod(withRulesMethod, this, frameworkMethod, testInstance,
statement);
}
return statement;
}
/**
* Returns <code>true</code> if {@link Ignore &#064;Ignore} is present for
* the supplied {@link FrameworkMethod test method} or if the test method is