Class DirtiesContextBeforeModestestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstracttestExecutionListener
org.springframework.test.context.support.AbstractDirtiesContexttestExecutionListener
org.springframework.test.context.support.DirtiesContextBeforeModestestExecutionListener
- All Implemented Interfaces:
Ordered, testExecutionListener
public class DirtiesContextBeforeModestestExecutionListener
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
BEFORE_METHOD and test classes with the
class mode set to
BEFORE_EACH_test_METHOD or
BEFORE_CLASS. For support for AFTER
modes, see DirtiesContexttestExecutionListener.
When merging
testExecutionListeners with the defaults, this listener will
automatically be ordered before the DependencyInjectiontestExecutionListener;
otherwise, this listener must be manually configured to execute before the
DependencyInjectiontestExecutionListener.
- Since:
- 4.2
- Author:
- Sam Brannen
- See Also:
-
Field Summary
FieldsFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforetestClass(testContext testContext) If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toBEFORE_CLASS, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.voidbeforetestMethod(testContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toBEFORE_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toBEFORE_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 1500, which ensures that theDirtiesContextBeforeModestestExecutionListeneris ordered after theServlettestExecutionListenerand before theApplicationEventstestExecutionListenerand theBeanOverridetestExecutionListener.Methods inherited from class AbstractDirtiesContexttestExecutionListener
beforeOrAftertestClass, beforeOrAftertestMethod, dirtyContextMethods inherited from class AbstracttestExecutionListener
aftertestClass, aftertestExecution, aftertestMethod, beforetestExecution, preparetestInstance
-
Field Details
-
ORDER
-
-
Constructor Details
-
DirtiesContextBeforeModestestExecutionListener
public DirtiesContextBeforeModestestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns 1500, which ensures that theDirtiesContextBeforeModestestExecutionListeneris ordered after theServlettestExecutionListenerand before theApplicationEventstestExecutionListenerand theBeanOverridetestExecutionListener.- Specified by:
getOrderin interfaceOrdered- Specified by:
getOrderin classAbstractDirtiesContexttestExecutionListener- Returns:
- the order value
- See Also:
-
beforetestClass
If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toBEFORE_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:
beforetestClassin interfacetestExecutionListener- Overrides:
beforetestClassin classAbstracttestExecutionListener- Parameters:
testContext- the test context for the test; nevernull- Throws:
Exception- allows any exception to propagate
-
beforetestMethod
If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toBEFORE_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toBEFORE_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:
beforetestMethodin interfacetestExecutionListener- Overrides:
beforetestMethodin classAbstracttestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- Throws:
Exception- allows any exception to propagate- See Also:
-