Delete deprecated code in the TestContext framework
This commit deletes the deprecated @ExpectedException and @NotTransactional annotations, supporting code, and related Javadoc and reference documentation. Issue: SPR-10499
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Test annotation to indicate that a test method is required to throw the
|
||||
* specified exception.
|
||||
*
|
||||
* @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();
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Test annotation to indicate that a method is <i>not transactional</i>.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @since 2.0
|
||||
* @deprecated as of Spring 3.0, in favor of moving the non-transactional test
|
||||
* method to a separate (non-transactional) test class or to a
|
||||
* {@link org.springframework.test.context.transaction.BeforeTransaction
|
||||
* @BeforeTransaction} or
|
||||
* {@link org.springframework.test.context.transaction.AfterTransaction
|
||||
* @AfterTransaction} method.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@Deprecated
|
||||
public @interface NotTransactional {
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -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;
|
||||
import org.springframework.test.annotation.Timed;
|
||||
@@ -64,7 +63,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>{@link Test#expected() @Test(expected=...)}</li>
|
||||
* <li>{@link ExpectedException @ExpectedException}</li>
|
||||
* <li>{@link Test#timeout() @Test(timeout=...)}</li>
|
||||
* <li>{@link Timed @Timed}</li>
|
||||
* <li>{@link Repeat @Repeat}</li>
|
||||
@@ -349,9 +347,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
/**
|
||||
* Get the {@code exception} that the supplied {@link FrameworkMethod
|
||||
* test method} is expected to throw.
|
||||
* <p>Supports both Spring's {@link ExpectedException @ExpectedException(...)}
|
||||
* and JUnit's {@link Test#expected() @Test(expected=...)} annotations, but
|
||||
* not both simultaneously.
|
||||
* <p>Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation.
|
||||
* @return the expected exception, or {@code null} if none was specified
|
||||
*/
|
||||
protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
|
||||
@@ -359,20 +355,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
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);
|
||||
|
||||
if (springExpectedException != null && junitExpectedException != null) {
|
||||
String msg = "Test method [" + frameworkMethod.getMethod()
|
||||
+ "] has been configured with Spring's @ExpectedException(" + springExpectedException.getName()
|
||||
+ ".class) and JUnit's @Test(expected=" + junitExpectedException.getName()
|
||||
+ ".class) annotations. "
|
||||
+ "Only one declaration of an 'expected exception' is permitted per test method.";
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
|
||||
return springExpectedException != null ? springExpectedException : junitExpectedException;
|
||||
return junitExpectedException;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -35,7 +35,6 @@ import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.test.annotation.NotTransactional;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.TestContext;
|
||||
import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||
@@ -56,15 +55,12 @@ import org.springframework.util.StringUtils;
|
||||
* {@code TestExecutionListener} that provides support for executing tests
|
||||
* within transactions by honoring the
|
||||
* {@link org.springframework.transaction.annotation.Transactional @Transactional}
|
||||
* and {@link NotTransactional @NotTransactional} annotations. Expects a
|
||||
* {@link PlatformTransactionManager} bean to be defined in the Spring
|
||||
* {@link ApplicationContext} for the test.
|
||||
* annotation. Expects a {@link PlatformTransactionManager} bean to be defined in the
|
||||
* Spring {@link ApplicationContext} for the test.
|
||||
*
|
||||
* <p>Changes to the database during a test that is run with {@code @Transactional}
|
||||
* will be run within a transaction that will, by default, be automatically
|
||||
* <em>rolled back</em> after completion of the test; whereas, changes to the
|
||||
* database during a test that is run with {@code @NotTransactional} will
|
||||
* <strong>not</strong> be run within a transaction. Test methods that are not
|
||||
* <em>rolled back</em> after completion of the test. Test methods that are not
|
||||
* annotated with {@code @Transactional} (at the class or method level) will not
|
||||
* be run within a transaction.
|
||||
*
|
||||
@@ -93,7 +89,6 @@ import org.springframework.util.StringUtils;
|
||||
* @see TransactionConfiguration
|
||||
* @see TransactionManagementConfigurer
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.NotTransactional
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see BeforeTransaction
|
||||
* @see AfterTransaction
|
||||
@@ -128,7 +123,6 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
* {@code @BeforeTransaction} methods will not be invoked, and a transaction
|
||||
* will not be started.
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.NotTransactional
|
||||
* @see #getTransactionManager(TestContext, String)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@@ -142,10 +136,6 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
+ "Invoke endTransaction() before startNewTransaction().");
|
||||
}
|
||||
|
||||
if (testMethod.isAnnotationPresent(NotTransactional.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlatformTransactionManager tm = null;
|
||||
TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod,
|
||||
testContext.getTestClass());
|
||||
@@ -162,10 +152,15 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
logger.debug("Explicit transaction definition [" + transactionAttribute + "] found for test context "
|
||||
+ testContext);
|
||||
}
|
||||
tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
|
||||
}
|
||||
|
||||
if (tm != null) {
|
||||
if (transactionAttribute.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
|
||||
}
|
||||
|
||||
if (tm != null) {
|
||||
TransactionContext txContext = new TransactionContext(tm, transactionAttribute);
|
||||
runBeforeTransactionMethods(testContext);
|
||||
startNewTransaction(testContext, txContext);
|
||||
|
||||
Reference in New Issue
Block a user