Class AbstractDirtiesContexttestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstracttestExecutionListener
org.springframework.test.context.support.AbstractDirtiesContexttestExecutionListener
- All Implemented Interfaces:
Ordered, testExecutionListener
- Direct Known Subclasses:
DirtiesContextBeforeModestestExecutionListener, DirtiesContexttestExecutionListener
public abstract class AbstractDirtiesContexttestExecutionListener
extends AbstracttestExecutionListener
Abstract base class for
testExecutionListener implementations that
provide support for marking the ApplicationContext associated with
a test as dirty for both test classes and test methods annotated
with the @DirtiesContext annotation.
The core functionality for this class was extracted from
DirtiesContexttestExecutionListener in Spring Framework 4.2.
- Since:
- 4.2
- Author:
- Sam Brannen, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbeforeOrAftertestClass(testContext testContext, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstracttestExecutionListener.beforetestClass(testContext)andAbstracttestExecutionListener.aftertestClass(testContext)by dirtying the context if appropriate (i.e., according to the required mode).protected voidbeforeOrAftertestMethod(testContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstracttestExecutionListener.beforetestMethod(testContext)andAbstracttestExecutionListener.aftertestMethod(testContext)by dirtying the context if appropriate (i.e., according to the required modes).protected voiddirtyContext(testContext testContext, @Nullable DirtiesContext.HierarchyMode hierarchyMode) Mark the application context of the supplied test context as dirty and setREINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.abstract intgetOrder()The default implementation returnsOrdered.LOWEST_PRECEDENCE, thereby ensuring that custom listeners are ordered after default listeners supplied by the framework.Methods inherited from class AbstracttestExecutionListener
aftertestClass, aftertestExecution, aftertestMethod, beforetestClass, beforetestExecution, beforetestMethod, preparetestInstance
-
Constructor Details
-
AbstractDirtiesContexttestExecutionListener
public AbstractDirtiesContexttestExecutionListener()
-
-
Method Details
-
getOrder
public abstract int getOrder()Description copied from class:AbstracttestExecutionListenerThe default implementation returnsOrdered.LOWEST_PRECEDENCE, thereby ensuring that custom listeners are ordered after default listeners supplied by the framework. Can be overridden by subclasses as necessary.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstracttestExecutionListener- Returns:
- the order value
- See Also:
-
dirtyContext
protected void dirtyContext(testContext testContext, @Nullable DirtiesContext.HierarchyMode hierarchyMode) Mark the application context of the supplied test context as dirty and setREINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.- Parameters:
testContext- the test context whose application context should be marked as dirtyhierarchyMode- the context cache clearing mode to be applied if the context is part of a hierarchy; may benull- Since:
- 3.2.2
-
beforeOrAftertestMethod
protected void beforeOrAftertestMethod(testContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) throws Exception Perform the actual work forAbstracttestExecutionListener.beforetestMethod(testContext)andAbstracttestExecutionListener.aftertestMethod(testContext)by dirtying the context if appropriate (i.e., according to the required modes).- Parameters:
testContext- the test context whose application context should potentially be marked as dirty; nevernullrequiredMethodMode- the method mode required for a context to be marked dirty in the current phase; nevernullrequiredClassMode- the class mode required for a context to be marked dirty in the current phase; nevernull- Throws:
Exception- allows any exception to propagate- Since:
- 4.2
- See Also:
-
beforeOrAftertestClass
protected void beforeOrAftertestClass(testContext testContext, DirtiesContext.ClassMode requiredClassMode) throws Exception Perform the actual work forAbstracttestExecutionListener.beforetestClass(testContext)andAbstracttestExecutionListener.aftertestClass(testContext)by dirtying the context if appropriate (i.e., according to the required mode).- Parameters:
testContext- the test context whose application context should potentially be marked as dirty; nevernullrequiredClassMode- the class mode required for a context to be marked dirty in the current phase; nevernull- Throws:
Exception- allows any exception to propagate- Since:
- 4.2
- See Also:
-