Class DirtiesContextTestExecutionListener
- java.lang.Object
- org.springframework.test.context.support.AbstractTestExecutionListener
- org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener
- org.springframework.test.context.support.DirtiesContextTestExecutionListener
- All Implemented Interfaces:
Ordered
,TestExecutionListener
public class DirtiesContextTestExecutionListener extends AbstractDirtiesContextTestExecutionListener
TestExecutionListener
which provides support for marking theApplicationContext
associated with a test as dirty for both test classes and test methods annotated with the@DirtiesContext
annotation.This listener supports test methods with the method mode set to
AFTER_METHOD
and test classes with the class mode set toAFTER_EACH_TEST_METHOD
orAFTER_CLASS
. For support for BEFORE modes, seeDirtiesContextBeforeModesTestExecutionListener
.When merging
TestExecutionListeners
with the defaults, this listener will automatically be ordered after theDependencyInjectionTestExecutionListener
; otherwise, this listener must be manually configured to execute after theDependencyInjectionTestExecutionListener
.- Since:
- 2.5
- Author:
- Sam Brannen
- See Also:
DirtiesContext
,DirtiesContextBeforeModesTestExecutionListener
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description DirtiesContextTestExecutionListener()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterTestClass(TestContext testContext)
If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toAFTER_CLASS
, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.void
afterTestMethod(TestContext testContext)
If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toAFTER_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toAFTER_EACH_TEST_METHOD
, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.int
getOrder()
Returns3000
.Methods inherited from class org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener
beforeOrAfterTestClass, beforeOrAfterTestMethod, dirtyContext
Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
beforeTestClass, beforeTestMethod, prepareTestInstance
Constructor Detail
DirtiesContextTestExecutionListener
public DirtiesContextTestExecutionListener()
Method Detail
getOrder
public final int getOrder()
Returns3000
.- Specified by:
getOrder
in interfaceOrdered
- Specified by:
getOrder
in classAbstractDirtiesContextTestExecutionListener
- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
afterTestMethod
public void afterTestMethod(TestContext testContext) throws Exception
If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toAFTER_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toAFTER_EACH_TEST_METHOD
, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.- Specified by:
afterTestMethod
in interfaceTestExecutionListener
- Overrides:
afterTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method was executed; nevernull
- Throws:
Exception
- allows any exception to propagate
afterTestClass
public void afterTestClass(TestContext testContext) throws Exception
If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toAFTER_CLASS
, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTE
in the test context will be set totrue
.- Specified by:
afterTestClass
in interfaceTestExecutionListener
- Overrides:
afterTestClass
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context for the test; nevernull
- Throws:
Exception
- allows any exception to propagate