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 forTestExecutionListener
implementations that provide support for marking theApplicationContext
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:
DirtiesContext
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description AbstractDirtiesContextTestExecutionListener()
Method Summary
Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestMethod, beforeTestClass, beforeTestMethod, prepareTestInstance
Constructor Detail
AbstractDirtiesContextTestExecutionListener
public AbstractDirtiesContextTestExecutionListener()
Method Detail
getOrder
public abstract int getOrder()
Description copied from class:AbstractTestExecutionListener
The 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:
getOrder
in interfaceOrdered
- Overrides:
getOrder
in classAbstractTestExecutionListener
- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
dirtyContext
protected void dirtyContext(TestContext testContext, DirtiesContext.HierarchyMode hierarchyMode)
Mark the application context of the supplied test context as dirty and setREINJECT_DEPENDENCIES_ATTRIBUTE
in 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; nevernull
requiredMethodMode
- the method mode required for a context to be marked dirty in the current phase; nevernull
requiredClassMode
- 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:
dirtyContext(org.springframework.test.context.TestContext, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
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; nevernull
requiredClassMode
- 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:
dirtyContext(org.springframework.test.context.TestContext, org.springframework.test.annotation.DirtiesContext.HierarchyMode)