public abstract class AbstractDirtiesContextTestExecutionListener extends AbstractTestExecutionListener
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.
DirtiesContext
Modifier and Type | Field and Description |
---|---|
private static Log |
logger |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
AbstractDirtiesContextTestExecutionListener() |
afterTestClass, afterTestMethod, beforeTestClass, beforeTestMethod, prepareTestInstance
public AbstractDirtiesContextTestExecutionListener()
public abstract int getOrder()
AbstractTestExecutionListener
Ordered.LOWEST_PRECEDENCE
,
thereby ensuring that custom listeners are ordered after default
listeners supplied by the framework. Can be overridden by subclasses
as necessary.getOrder
in interface Ordered
getOrder
in class AbstractTestExecutionListener
protected void dirtyContext(TestContext testContext, DirtiesContext.HierarchyMode hierarchyMode)
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context to true
.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 be null
protected void beforeOrAfterTestMethod(TestContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) throws java.lang.Exception
AbstractTestExecutionListener.beforeTestMethod(org.springframework.test.context.TestContext)
and AbstractTestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)
by dirtying the context if appropriate (i.e., according to the required modes).testContext
- the test context whose application context should
potentially be marked as dirty; never null
requiredMethodMode
- the method mode required for a context to
be marked dirty in the current phase; never null
requiredClassMode
- the class mode required for a context to
be marked dirty in the current phase; never null
java.lang.Exception
- allows any exception to propagatedirtyContext(org.springframework.test.context.TestContext, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
protected void beforeOrAfterTestClass(TestContext testContext, DirtiesContext.ClassMode requiredClassMode) throws java.lang.Exception
AbstractTestExecutionListener.beforeTestClass(org.springframework.test.context.TestContext)
and AbstractTestExecutionListener.afterTestClass(org.springframework.test.context.TestContext)
by dirtying the context if appropriate (i.e., according to the required mode).testContext
- the test context whose application context should
potentially be marked as dirty; never null
requiredClassMode
- the class mode required for a context to
be marked dirty in the current phase; never null
java.lang.Exception
- allows any exception to propagatedirtyContext(org.springframework.test.context.TestContext, org.springframework.test.annotation.DirtiesContext.HierarchyMode)