Browse Source

[SPR-8627] Deprecated @ExpectedException.

pull/7/head
Sam Brannen 15 years ago
parent
commit
381ab6fcc2
  1. 3
      org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java
  2. 9
      org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java
  3. 7
      org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java

3
org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java

@ -29,10 +29,13 @@ import java.lang.annotation.Target; @@ -29,10 +29,13 @@ import java.lang.annotation.Target;
* @author Rod Johnson
* @author Sam Brannen
* @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
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Deprecated
public @interface ExpectedException {
Class<? extends Throwable> value();

9
org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java

@ -34,7 +34,6 @@ import org.junit.runners.BlockJUnit4ClassRunner; @@ -34,7 +34,6 @@ import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.springframework.test.annotation.ExpectedException;
import org.springframework.test.annotation.ProfileValueUtils;
import org.springframework.test.annotation.Repeat;
@ -86,6 +85,7 @@ import org.springframework.util.ReflectionUtils; @@ -86,6 +85,7 @@ import org.springframework.util.ReflectionUtils;
* @since 2.5
* @see TestContextManager
*/
@SuppressWarnings("deprecation")
public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
private static final Log logger = LogFactory.getLog(SpringJUnit4ClassRunner.class);
@ -282,6 +282,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -282,6 +282,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
Object testInstance;
try {
testInstance = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
@ -355,8 +356,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -355,8 +356,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
*/
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
Class<? extends Throwable> junitExpectedException = (testAnnotation != null &&
testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
Class<? extends Throwable> junitExpectedException = (testAnnotation != null
&& testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
@ -438,7 +439,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -438,7 +439,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
* @see RunBeforeTestMethodCallbacks
*/
@Override
@SuppressWarnings("deprecation")
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
@ -453,7 +453,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -453,7 +453,6 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
* @see RunAfterTestMethodCallbacks
*/
@Override
@SuppressWarnings("deprecation")
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),

7
org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -38,11 +38,12 @@ import org.springframework.test.context.TestExecutionListeners; @@ -38,11 +38,12 @@ import org.springframework.test.context.TestExecutionListeners;
* @author Sam Brannen
* @since 3.0
*/
@SuppressWarnings("deprecation")
@RunWith(JUnit4.class)
public class ExpectedExceptionSpringRunnerTests {
@Test
public void timedTests() throws Exception {
public void expectedExceptions() throws Exception {
Class<ExpectedExceptionSpringRunnerTestCase> testClass = ExpectedExceptionSpringRunnerTestCase.class;
TrackingRunListener listener = new TrackingRunListener();
RunNotifier notifier = new RunNotifier();
@ -59,7 +60,7 @@ public class ExpectedExceptionSpringRunnerTests { @@ -59,7 +60,7 @@ public class ExpectedExceptionSpringRunnerTests {
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( {})
@TestExecutionListeners({})
public static final class ExpectedExceptionSpringRunnerTestCase {
// Should Pass.

Loading…
Cancel
Save