Skip to content

Commit 381ab6f

Browse files
committed
[SPR-8627] Deprecated @ExpectedException.
1 parent 960082d commit 381ab6f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@
2929
* @author Rod Johnson
3030
* @author Sam Brannen
3131
* @since 2.0
32+
* @deprecated as of Spring 3.1 in favor of using built-in support for declaring
33+
* expected exceptions in the underlying testing framework (e.g., JUnit, TestNG, etc.)
3234
*/
3335
@Documented
3436
@Retention(RetentionPolicy.RUNTIME)
3537
@Target(ElementType.METHOD)
38+
@Deprecated
3639
public @interface ExpectedException {
3740

3841
Class<? extends Throwable> value();

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.junit.runners.model.FrameworkMethod;
3535
import org.junit.runners.model.InitializationError;
3636
import org.junit.runners.model.Statement;
37-
3837
import org.springframework.test.annotation.ExpectedException;
3938
import org.springframework.test.annotation.ProfileValueUtils;
4039
import org.springframework.test.annotation.Repeat;
@@ -86,6 +85,7 @@
8685
* @since 2.5
8786
* @see TestContextManager
8887
*/
88+
@SuppressWarnings("deprecation")
8989
public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
9090

9191
private static final Log logger = LogFactory.getLog(SpringJUnit4ClassRunner.class);
@@ -282,6 +282,7 @@ protected Statement methodBlock(FrameworkMethod frameworkMethod) {
282282
Object testInstance;
283283
try {
284284
testInstance = new ReflectiveCallable() {
285+
285286
@Override
286287
protected Object runReflectiveCall() throws Throwable {
287288
return createTest();
@@ -355,8 +356,8 @@ protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod,
355356
*/
356357
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
357358
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
358-
Class<? extends Throwable> junitExpectedException = (testAnnotation != null &&
359-
testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
359+
Class<? extends Throwable> junitExpectedException = (testAnnotation != null
360+
&& testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
360361

361362
ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
362363
Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
@@ -438,7 +439,6 @@ protected long getSpringTimeout(FrameworkMethod frameworkMethod) {
438439
* @see RunBeforeTestMethodCallbacks
439440
*/
440441
@Override
441-
@SuppressWarnings("deprecation")
442442
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
443443
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
444444
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
@@ -453,7 +453,6 @@ protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInst
453453
* @see RunAfterTestMethodCallbacks
454454
*/
455455
@Override
456-
@SuppressWarnings("deprecation")
457456
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
458457
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
459458
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,11 +38,12 @@
3838
* @author Sam Brannen
3939
* @since 3.0
4040
*/
41+
@SuppressWarnings("deprecation")
4142
@RunWith(JUnit4.class)
4243
public class ExpectedExceptionSpringRunnerTests {
4344

4445
@Test
45-
public void timedTests() throws Exception {
46+
public void expectedExceptions() throws Exception {
4647
Class<ExpectedExceptionSpringRunnerTestCase> testClass = ExpectedExceptionSpringRunnerTestCase.class;
4748
TrackingRunListener listener = new TrackingRunListener();
4849
RunNotifier notifier = new RunNotifier();
@@ -59,7 +60,7 @@ public void timedTests() throws Exception {
5960

6061

6162
@RunWith(SpringJUnit4ClassRunner.class)
62-
@TestExecutionListeners( {})
63+
@TestExecutionListeners({})
6364
public static final class ExpectedExceptionSpringRunnerTestCase {
6465

6566
// Should Pass.

0 commit comments

Comments
 (0)