Require JUnit 4.12 or higher in the TestContext framework
Issue: SPR-13275
This commit is contained in:
@@ -70,7 +70,7 @@ import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
* and specify your runner of choice via {@link RunWith @RunWith(...)}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.1, this class requires JUnit 4.9 or higher.
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
|
||||
@@ -73,7 +73,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* and specify your runner of choice via {@link org.junit.runner.RunWith @RunWith(...)}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.1, this class requires JUnit 4.9 or higher.
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.test.context.junit4;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -75,7 +76,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* <p>If you would like to use the Spring TestContext Framework with a runner
|
||||
* other than this one, use {@link SpringClassRule} and {@link SpringMethodRule}.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.1, this class requires JUnit 4.9 or higher.
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
@@ -92,27 +93,20 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final Method withRulesMethod;
|
||||
|
||||
// Used by RunAfterTestClassCallbacks and RunAfterTestMethodCallbacks
|
||||
private static final String MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME = "org.junit.runners.model.MultipleFailureException";
|
||||
|
||||
static {
|
||||
boolean junit4dot9Present = ClassUtils.isPresent(MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME,
|
||||
SpringJUnit4ClassRunner.class.getClassLoader());
|
||||
if (!junit4dot9Present) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Failed to find class [%s]: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.",
|
||||
MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME));
|
||||
if (!ClassUtils.isPresent("org.junit.internal.Throwables", SpringJUnit4ClassRunner.class.getClassLoader())) {
|
||||
throw new IllegalStateException("SpringJUnit4ClassRunner requires JUnit 4.12 or higher.");
|
||||
}
|
||||
|
||||
withRulesMethod = ReflectionUtils.findMethod(SpringJUnit4ClassRunner.class, "withRules",
|
||||
FrameworkMethod.class, Object.class, Statement.class);
|
||||
if (withRulesMethod == null) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to find withRules() method: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.");
|
||||
throw new IllegalStateException("SpringJUnit4ClassRunner requires JUnit 4.12 or higher.");
|
||||
}
|
||||
ReflectionUtils.makeAccessible(withRulesMethod);
|
||||
}
|
||||
|
||||
|
||||
private final TestContextManager testContextManager;
|
||||
|
||||
|
||||
@@ -376,8 +370,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
statement = new SpringFailOnTimeout(next, springTimeout);
|
||||
}
|
||||
else if (junitTimeout > 0) {
|
||||
// TODO Use FailOnTimeout.builder() once JUnit 4.12 is the minimum supported version.
|
||||
statement = new FailOnTimeout(next, junitTimeout);
|
||||
statement = FailOnTimeout.builder().withTimeout(junitTimeout, TimeUnit.MILLISECONDS).build(next);
|
||||
}
|
||||
else {
|
||||
statement = next;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* Support classes for integrating the <em>Spring TestContext Framework</em> with JUnit.
|
||||
* Support classes for integrating the <em>Spring TestContext Framework</em>
|
||||
* with JUnit 4.12 or higher.
|
||||
*/
|
||||
package org.springframework.test.context.junit4;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
@@ -76,7 +77,7 @@ import org.springframework.util.ClassUtils;
|
||||
* <li>{@link org.springframework.test.annotation.IfProfileValue @IfProfileValue}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This class requires JUnit 4.9 or higher.
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Philippe Marschall
|
||||
@@ -96,16 +97,9 @@ public class SpringClassRule implements TestRule {
|
||||
private static final Map<Class<?>, TestContextManager> testContextManagerCache =
|
||||
new ConcurrentHashMap<Class<?>, TestContextManager>(64);
|
||||
|
||||
// Used by RunAfterTestClassCallbacks
|
||||
private static final String MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME = "org.junit.runners.model.MultipleFailureException";
|
||||
|
||||
static {
|
||||
boolean junit4dot9Present = ClassUtils.isPresent(MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME,
|
||||
SpringClassRule.class.getClassLoader());
|
||||
if (!junit4dot9Present) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Failed to find class [%s]: SpringClassRule requires JUnit 4.9 or higher.",
|
||||
MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME));
|
||||
if (!ClassUtils.isPresent("org.junit.internal.Throwables", SpringClassRule.class.getClassLoader())) {
|
||||
throw new IllegalStateException("SpringClassRule requires JUnit 4.12 or higher.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
@@ -79,7 +80,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* <li>{@link org.springframework.test.annotation.IfProfileValue @IfProfileValue}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p><strong>NOTE:</strong> This class requires JUnit 4.9 or higher.
|
||||
* <p><strong>NOTE:</strong> As of Spring Framework 4.3, this class requires JUnit 4.12 or higher.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Philippe Marschall
|
||||
@@ -93,16 +94,9 @@ public class SpringMethodRule implements MethodRule {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringMethodRule.class);
|
||||
|
||||
// Used by RunAfterTestMethodCallbacks
|
||||
private static final String MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME = "org.junit.runners.model.MultipleFailureException";
|
||||
|
||||
static {
|
||||
boolean junit4dot9Present = ClassUtils.isPresent(MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME,
|
||||
SpringMethodRule.class.getClassLoader());
|
||||
if (!junit4dot9Present) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Failed to find class [%s]: SpringMethodRule requires JUnit 4.9 or higher.",
|
||||
MULTIPLE_FAILURE_EXCEPTION_CLASS_NAME));
|
||||
if (!ClassUtils.isPresent("org.junit.internal.Throwables", SpringMethodRule.class.getClassLoader())) {
|
||||
throw new IllegalStateException("SpringMethodRule requires JUnit 4.12 or higher.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.test.context.junit4.statements;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
@@ -76,27 +76,24 @@ public class ProfileValueChecker extends Statement {
|
||||
* will simply evaluate the next {@link Statement} in the execution chain.
|
||||
* @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class)
|
||||
* @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class)
|
||||
* @see org.junit.Assume
|
||||
* @throws AssumptionViolatedException if the test is disabled
|
||||
* @throws Throwable if evaluation of the next statement fails
|
||||
*/
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
if (this.testMethod == null) {
|
||||
if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testClass)) {
|
||||
// Invoke assumeTrue() with false to avoid direct reference to JUnit's
|
||||
// AssumptionViolatedException which exists in two packages as of JUnit 4.12.
|
||||
Annotation ann = AnnotationUtils.findAnnotation(this.testClass, IfProfileValue.class);
|
||||
Assume.assumeTrue(String.format(
|
||||
"Profile configured via [%s] is not enabled in this environment for test class [%s].",
|
||||
ann, this.testClass.getName()), false);
|
||||
throw new AssumptionViolatedException(
|
||||
String.format("Profile configured via [%s] is not enabled in this environment for test class [%s].",
|
||||
ann, this.testClass.getName()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!ProfileValueUtils.isTestEnabledInThisEnvironment(this.testMethod, this.testClass)) {
|
||||
// Invoke assumeTrue() with false to avoid direct reference to JUnit's
|
||||
// AssumptionViolatedException which exists in two packages as of JUnit 4.12.
|
||||
Assume.assumeTrue(String.format(
|
||||
"Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
|
||||
this.testMethod), false);
|
||||
throw new AssumptionViolatedException(String.format(
|
||||
"Profile configured via @IfProfileValue is not enabled in this environment for test method [%s].",
|
||||
this.testMethod));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,13 +80,7 @@ public class RunAfterTestClassCallbacks extends Statement {
|
||||
errors.add(ex);
|
||||
}
|
||||
|
||||
if (errors.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (errors.size() == 1) {
|
||||
throw errors.get(0);
|
||||
}
|
||||
throw new MultipleFailureException(errors);
|
||||
MultipleFailureException.assertEmpty(errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,13 +97,7 @@ public class RunAfterTestMethodCallbacks extends Statement {
|
||||
errors.add(ex);
|
||||
}
|
||||
|
||||
if (errors.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (errors.size() == 1) {
|
||||
throw errors.get(0);
|
||||
}
|
||||
throw new MultipleFailureException(errors);
|
||||
MultipleFailureException.assertEmpty(errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user