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 org.springframework.core.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(org.springframework.test.context.TestContext)andAbstractTestExecutionListener.afterTestClass(org.springframework.test.context.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(org.springframework.test.context.TestContext)andAbstractTestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)by dirtying the context if appropriate (i.e., according to the required modes).protected voiddirtyContext(TestContext testContext, 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 org.springframework.test.context.support.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(org.springframework.test.context.TestContext)andAbstractTestExecutionListener.afterTestMethod(org.springframework.test.context.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(org.springframework.test.context.TestContext)andAbstractTestExecutionListener.afterTestClass(org.springframework.test.context.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:
-