Package org.springframework.test.context.support

# 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:
  `org.springframework.core.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:
  - `DirtiesContext`
  - `DirtiesContextTestExecutionListener`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ORDER`
The `order` value for this listener: 1500.

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

## Constructor Summary

Constructors
Constructor
Description
`DirtiesContextBeforeModesTestExecutionListener()`

## Method Summary

Modifier and Type
Method
Description
`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`.
`final int`
`getOrder()`
Returns 1500, which ensures that the `DirtiesContextBeforeModesTestExecutionListener` is ordered after the `ServletTestExecutionListener` and before the `ApplicationEventsTestExecutionListener` and the `BeanOverrideTestExecutionListener`.

### 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ORDER

public static final int ORDER
The `order` value for this listener: 1500.

Since:
  6.2.3
See Also:
  - Constant Field Values

## Constructor Details

### DirtiesContextBeforeModesTestExecutionListener

public DirtiesContextBeforeModesTestExecutionListener()

## Method Details

### getOrder

public final int getOrder()
Returns 1500, which ensures that the `DirtiesContextBeforeModesTestExecutionListener` is ordered after the `ServletTestExecutionListener` and before the `ApplicationEventsTestExecutionListener` and the `BeanOverrideTestExecutionListener`.

Specified by:
  `getOrder` in interface `org.springframework.core.Ordered`
Specified by:
  `getOrder` in class `AbstractDirtiesContextTestExecutionListener`

### beforeTestClass

public void beforeTestClass(TestContext testContext) throws Exception
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`.

Specified by:
  `beforeTestClass` in interface `TestExecutionListener`
Overrides:
  `beforeTestClass` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context for the test; never `null`
Throws:
  `Exception` - allows any exception to propagate

### beforeTestMethod

public void beforeTestMethod(TestContext testContext) throws Exception
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`.

Specified by:
  `beforeTestMethod` in interface `TestExecutionListener`
Overrides:
  `beforeTestMethod` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context in which the test method will be executed; never `null`
Throws:
  `Exception` - allows any exception to propagate
See Also:
  - `TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)`
  - `TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)`
  - `TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)`