[SPR-8627] Deprecated @ExpectedException.
This commit is contained in:
parent
960082dbb0
commit
381ab6fcc2
|
@ -29,10 +29,13 @@ import java.lang.annotation.Target;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
* @deprecated as of Spring 3.1 in favor of using built-in support for declaring
|
||||||
|
* expected exceptions in the underlying testing framework (e.g., JUnit, TestNG, etc.)
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
|
@Deprecated
|
||||||
public @interface ExpectedException {
|
public @interface ExpectedException {
|
||||||
|
|
||||||
Class<? extends Throwable> value();
|
Class<? extends Throwable> value();
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.runners.BlockJUnit4ClassRunner;
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
import org.junit.runners.model.InitializationError;
|
import org.junit.runners.model.InitializationError;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.springframework.test.annotation.ExpectedException;
|
import org.springframework.test.annotation.ExpectedException;
|
||||||
import org.springframework.test.annotation.ProfileValueUtils;
|
import org.springframework.test.annotation.ProfileValueUtils;
|
||||||
import org.springframework.test.annotation.Repeat;
|
import org.springframework.test.annotation.Repeat;
|
||||||
|
@ -86,6 +85,7 @@ import org.springframework.util.ReflectionUtils;
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
* @see TestContextManager
|
* @see TestContextManager
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(SpringJUnit4ClassRunner.class);
|
private static final Log logger = LogFactory.getLog(SpringJUnit4ClassRunner.class);
|
||||||
|
@ -282,6 +282,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||||
Object testInstance;
|
Object testInstance;
|
||||||
try {
|
try {
|
||||||
testInstance = new ReflectiveCallable() {
|
testInstance = new ReflectiveCallable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object runReflectiveCall() throws Throwable {
|
protected Object runReflectiveCall() throws Throwable {
|
||||||
return createTest();
|
return createTest();
|
||||||
|
@ -355,8 +356,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||||
*/
|
*/
|
||||||
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
|
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
|
||||||
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
|
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
|
||||||
Class<? extends Throwable> junitExpectedException = (testAnnotation != null &&
|
Class<? extends Throwable> junitExpectedException = (testAnnotation != null
|
||||||
testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
|
&& testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
|
||||||
|
|
||||||
ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
|
ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
|
||||||
Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
|
Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
|
||||||
|
@ -438,7 +439,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||||
* @see RunBeforeTestMethodCallbacks
|
* @see RunBeforeTestMethodCallbacks
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
||||||
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
|
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
|
||||||
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
|
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
|
||||||
|
@ -453,7 +453,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||||
* @see RunAfterTestMethodCallbacks
|
* @see RunAfterTestMethodCallbacks
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
|
||||||
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
|
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
|
||||||
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),
|
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -38,11 +38,12 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class ExpectedExceptionSpringRunnerTests {
|
public class ExpectedExceptionSpringRunnerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void timedTests() throws Exception {
|
public void expectedExceptions() throws Exception {
|
||||||
Class<ExpectedExceptionSpringRunnerTestCase> testClass = ExpectedExceptionSpringRunnerTestCase.class;
|
Class<ExpectedExceptionSpringRunnerTestCase> testClass = ExpectedExceptionSpringRunnerTestCase.class;
|
||||||
TrackingRunListener listener = new TrackingRunListener();
|
TrackingRunListener listener = new TrackingRunListener();
|
||||||
RunNotifier notifier = new RunNotifier();
|
RunNotifier notifier = new RunNotifier();
|
||||||
|
@ -59,7 +60,7 @@ public class ExpectedExceptionSpringRunnerTests {
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@TestExecutionListeners( {})
|
@TestExecutionListeners({})
|
||||||
public static final class ExpectedExceptionSpringRunnerTestCase {
|
public static final class ExpectedExceptionSpringRunnerTestCase {
|
||||||
|
|
||||||
// Should Pass.
|
// Should Pass.
|
||||||
|
|
Loading…
Reference in New Issue