public class DirtiesContextTestExecutionListener extends AbstractTestExecutionListener
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.DirtiesContext
Modifier and Type | Field and Description |
---|---|
private static Log |
logger |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
DirtiesContextTestExecutionListener() |
Modifier and Type | Method and Description |
---|---|
void |
afterTestClass(TestContext testContext)
If the test class of the supplied test context
is annotated with
@DirtiesContext and the class mode is set to AFTER_CLASS , the application context of the test context will be
marked as dirty, and the
REINJECT_DEPENDENCIES_ATTRIBUTE in the test context will be set to
true . |
void |
afterTestMethod(TestContext testContext)
If the current test method of the supplied test
context is annotated with
@DirtiesContext and the method mode is set to AFTER_METHOD , or if the test class is
annotated with @DirtiesContext and the class mode is set to AFTER_EACH_TEST_METHOD , the
application context of the test context
will be marked as dirty and the
REINJECT_DEPENDENCIES_ATTRIBUTE in the test context will be set to true . |
private void |
beforeOrAfterTestClass(TestContext testContext,
java.lang.String phase,
DirtiesContext.ClassMode requiredClassMode)
Perform the actual work for
beforeTestClass(org.springframework.test.context.TestContext) and afterTestClass(org.springframework.test.context.TestContext) . |
private void |
beforeOrAfterTestMethod(TestContext testContext,
java.lang.String phase,
DirtiesContext.MethodMode requiredMethodMode,
DirtiesContext.ClassMode requiredClassMode)
Perform the actual work for
beforeTestMethod(org.springframework.test.context.TestContext) and afterTestMethod(org.springframework.test.context.TestContext) . |
void |
beforeTestClass(TestContext testContext)
If the test class of the supplied test context
is annotated with
@DirtiesContext and the class mode is set to BEFORE_CLASS , the application context of the test context will be
marked as dirty, and the
REINJECT_DEPENDENCIES_ATTRIBUTE in the test context will be set to
true . |
void |
beforeTestMethod(TestContext testContext)
If the current test method of the supplied test
context is annotated with
@DirtiesContext and the method mode is set to BEFORE_METHOD , or if the test class is
annotated with @DirtiesContext and the class mode is set to BEFORE_EACH_TEST_METHOD , the
application context of the test context
will be marked as dirty and the
REINJECT_DEPENDENCIES_ATTRIBUTE in the test context will be set to true . |
protected void |
dirtyContext(TestContext testContext,
DirtiesContext.HierarchyMode hierarchyMode)
Marks the application context of the supplied
test context as
dirty
and sets
REINJECT_DEPENDENCIES_ATTRIBUTE in the test context to true . |
int |
getOrder()
Returns
3000 . |
prepareTestInstance
public final int getOrder()
3000
.getOrder
in interface Ordered
getOrder
in class AbstractTestExecutionListener
public void beforeTestClass(TestContext testContext) throws java.lang.Exception
@DirtiesContext
and the class mode is set to BEFORE_CLASS
, the application context of the test context will be
marked as dirty, and the
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set to
true
.beforeTestClass
in interface TestExecutionListener
beforeTestClass
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null
java.lang.Exception
- allows any exception to propagatepublic void beforeTestMethod(TestContext testContext) throws java.lang.Exception
@DirtiesContext
and the method mode is set to BEFORE_METHOD
, or if the test class is
annotated with @DirtiesContext
and the class mode is set to BEFORE_EACH_TEST_METHOD
, the
application context of the test context
will be marked as dirty and the
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set to true
.beforeTestMethod
in interface TestExecutionListener
beforeTestMethod
in class AbstractTestExecutionListener
testContext
- the test context in which the test method will be
executed; never null
java.lang.Exception
- allows any exception to propagatepublic void afterTestMethod(TestContext testContext) throws java.lang.Exception
@DirtiesContext
and the method mode is set to AFTER_METHOD
, or if the test class is
annotated with @DirtiesContext
and the class mode is set to AFTER_EACH_TEST_METHOD
, the
application context of the test context
will be marked as dirty and the
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set to true
.afterTestMethod
in interface TestExecutionListener
afterTestMethod
in class AbstractTestExecutionListener
testContext
- the test context in which the test method was
executed; never null
java.lang.Exception
- allows any exception to propagatepublic void afterTestClass(TestContext testContext) throws java.lang.Exception
@DirtiesContext
and the class mode is set to AFTER_CLASS
, the application context of the test context will be
marked as dirty, and the
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set to
true
.afterTestClass
in interface TestExecutionListener
afterTestClass
in class AbstractTestExecutionListener
testContext
- the test context for the test; never null
java.lang.Exception
- allows any exception to propagateprotected void dirtyContext(TestContext testContext, DirtiesContext.HierarchyMode hierarchyMode)
REINJECT_DEPENDENCIES_ATTRIBUTE
in the test context to true
.testContext
- the test context whose application context should
marked as dirtyhierarchyMode
- the context cache clearing mode to be applied if the
context is part of a hierarchy; may be null
private void beforeOrAfterTestMethod(TestContext testContext, java.lang.String phase, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) throws java.lang.Exception
beforeTestMethod(org.springframework.test.context.TestContext)
and afterTestMethod(org.springframework.test.context.TestContext)
.java.lang.Exception
private void beforeOrAfterTestClass(TestContext testContext, java.lang.String phase, DirtiesContext.ClassMode requiredClassMode) throws java.lang.Exception
beforeTestClass(org.springframework.test.context.TestContext)
and afterTestClass(org.springframework.test.context.TestContext)
.java.lang.Exception