diff --git a/org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java b/org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java index dffd43edb2..b5f8584dfe 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java +++ b/org.springframework.test/src/main/java/org/springframework/test/annotation/ExpectedException.java @@ -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 value(); diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java index e4967d8d54..2d184156ee 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java @@ -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; * @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 { Object testInstance; try { testInstance = new ReflectiveCallable() { + @Override protected Object runReflectiveCall() throws Throwable { return createTest(); @@ -355,8 +356,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { */ protected Class getExpectedException(FrameworkMethod frameworkMethod) { Test testAnnotation = frameworkMethod.getAnnotation(Test.class); - Class junitExpectedException = (testAnnotation != null && - testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null); + Class junitExpectedException = (testAnnotation != null + && testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null); ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class); Class springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null); @@ -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 { * @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(), diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java index 1ce10ff9ca..b81d336347 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java @@ -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; * @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 testClass = ExpectedExceptionSpringRunnerTestCase.class; TrackingRunListener listener = new TrackingRunListener(); RunNotifier notifier = new RunNotifier(); @@ -59,7 +60,7 @@ public class ExpectedExceptionSpringRunnerTests { @RunWith(SpringJUnit4ClassRunner.class) - @TestExecutionListeners( {}) + @TestExecutionListeners({}) public static final class ExpectedExceptionSpringRunnerTestCase { // Should Pass.