Class DirtiesContextBeforeModesTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener
org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
- All Implemented Interfaces:
Ordered
,TestExecutionListener
public class DirtiesContextBeforeModesTestExecutionListener
extends AbstractDirtiesContextTestExecutionListener
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.
This listener supports test methods with the
method mode set to
BEFORE_METHOD
and test classes with the
class mode set to
BEFORE_EACH_TEST_METHOD
or
BEFORE_CLASS
. For support for AFTER
modes, see DirtiesContextTestExecutionListener
.
When merging
TestExecutionListeners
with the defaults, this listener will
automatically be ordered before the DependencyInjectionTestExecutionListener
;
otherwise, this listener must be manually configured to execute before the
DependencyInjectionTestExecutionListener
.
- Since:
- 4.2
- Author:
- Sam Brannen
- See Also:
-
Field Summary
FieldsFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeTestClass
(TestContext testContext) If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toBEFORE_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
beforeTestMethod
(TestContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toBEFORE_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toBEFORE_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
.final int
getOrder()
Returns 1500, which ensures that theDirtiesContextBeforeModesTestExecutionListener
is ordered after theServletTestExecutionListener
and before theApplicationEventsTestExecutionListener
and theBeanOverrideTestExecutionListener
.Methods inherited from class org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener
beforeOrAfterTestClass, beforeOrAfterTestMethod, dirtyContext
Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestExecution, prepareTestInstance
-
Field Details
-
ORDER
public static final int ORDERTheorder
value for this listener: 1500.- Since:
- 6.2.3
- See Also:
-
-
Constructor Details
-
DirtiesContextBeforeModesTestExecutionListener
public DirtiesContextBeforeModesTestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns 1500, which ensures that theDirtiesContextBeforeModesTestExecutionListener
is ordered after theServletTestExecutionListener
and before theApplicationEventsTestExecutionListener
and theBeanOverrideTestExecutionListener
.- Specified by:
getOrder
in interfaceOrdered
- Specified by:
getOrder
in classAbstractDirtiesContextTestExecutionListener
- Returns:
- the order value
- See Also:
-
beforeTestClass
If the test class of the supplied test context is annotated with@DirtiesContext
and the class mode is set toBEFORE_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:
beforeTestClass
in interfaceTestExecutionListener
- Overrides:
beforeTestClass
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context for the test; nevernull
- Throws:
Exception
- allows any exception to propagate
-
beforeTestMethod
If the current test method of the supplied test context is annotated with@DirtiesContext
and the method mode is set toBEFORE_METHOD
, or if the test class is annotated with@DirtiesContext
and the class mode is set toBEFORE_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:
beforeTestMethod
in interfaceTestExecutionListener
- Overrides:
beforeTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method will be executed; nevernull
- Throws:
Exception
- allows any exception to propagate- See Also:
-