Class DirtiesContexttestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstracttestExecutionListener
org.springframework.test.context.support.AbstractDirtiesContexttestExecutionListener
org.springframework.test.context.support.DirtiesContexttestExecutionListener
- All Implemented Interfaces:
Ordered, testExecutionListener
public class DirtiesContexttestExecutionListener
extends AbstractDirtiesContexttestExecutionListener
testExecutionListener which provides support for marking the
ApplicationContext associated with a test as dirty for
both test classes and test methods annotated with the
@DirtiesContext annotation.
This listener supports test methods with the
method mode set to
AFTER_METHOD and test classes with the
class mode set to
AFTER_EACH_test_METHOD or
AFTER_CLASS. For support for BEFORE
modes, see DirtiesContextBeforeModestestExecutionListener.
When merging
testExecutionListeners with the defaults, this listener will
automatically be ordered after the DependencyInjectiontestExecutionListener;
otherwise, this listener must be manually configured to execute after the
DependencyInjectiontestExecutionListener.
- Since:
- 2.5
- Author:
- Sam Brannen
- See Also:
-
Field Summary
FieldsFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaftertestClass(testContext testContext) If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toAFTER_CLASS, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.voidaftertestMethod(testContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toAFTER_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toAFTER_EACH_test_METHOD, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.final intgetOrder()Returns 3000, which ensures that theDirtiesContexttestExecutionListeneris ordered after theDependencyInjectiontestExecutionListenerand before theCommonCachestestExecutionListener.Methods inherited from class AbstractDirtiesContexttestExecutionListener
beforeOrAftertestClass, beforeOrAftertestMethod, dirtyContextMethods inherited from class AbstracttestExecutionListener
aftertestExecution, beforetestClass, beforetestExecution, beforetestMethod, preparetestInstance
-
Field Details
-
ORDER
-
-
Constructor Details
-
DirtiesContexttestExecutionListener
public DirtiesContexttestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns 3000, which ensures that theDirtiesContexttestExecutionListeneris ordered after theDependencyInjectiontestExecutionListenerand before theCommonCachestestExecutionListener.- Specified by:
getOrderin interfaceOrdered- Specified by:
getOrderin classAbstractDirtiesContexttestExecutionListener- Returns:
- the order value
- See Also:
-
aftertestMethod
If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toAFTER_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toAFTER_EACH_test_METHOD, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.- Specified by:
aftertestMethodin interfacetestExecutionListener- Overrides:
aftertestMethodin classAbstracttestExecutionListener- Parameters:
testContext- the test context in which the test method was executed; nevernull- Throws:
Exception- allows any exception to propagate- See Also:
-
aftertestClass
If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toAFTER_CLASS, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.- Specified by:
aftertestClassin interfacetestExecutionListener- Overrides:
aftertestClassin classAbstracttestExecutionListener- Parameters:
testContext- the test context for the test; nevernull- Throws:
Exception- allows any exception to propagate
-