Support @Mockito[Spy]Bean & @TestBean w/ @DirtiesContext "before method" modes
Closes gh-33783
This commit is contained in:
@@ -66,6 +66,8 @@ package org.springframework.test.context;
|
||||
* DirtiesContextBeforeModesTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.event.ApplicationEventsTestExecutionListener
|
||||
* ApplicationEventsTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
|
||||
* BeanOverrideTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.support.DependencyInjectionTestExecutionListener
|
||||
* DependencyInjectionTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.observation.MicrometerObservationRegistryTestExecutionListener
|
||||
@@ -82,8 +84,6 @@ package org.springframework.test.context;
|
||||
* EventPublishingTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.bean.override.mockito.MockitoResetTestExecutionListener
|
||||
* MockitoResetTestExecutionListener}</li>
|
||||
* <li>{@link org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
|
||||
* BeanOverrideTestExecutionListener}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Sam Brannen
|
||||
|
||||
@@ -82,6 +82,7 @@ public @interface TestExecutionListeners {
|
||||
* @see org.springframework.test.context.web.ServletTestExecutionListener
|
||||
* @see org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
|
||||
* @see org.springframework.test.context.event.ApplicationEventsTestExecutionListener
|
||||
* @see org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
|
||||
* @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener
|
||||
* @see org.springframework.test.context.support.DirtiesContextTestExecutionListener
|
||||
* @see org.springframework.test.context.support.CommonCachesTestExecutionListener
|
||||
@@ -89,7 +90,6 @@ public @interface TestExecutionListeners {
|
||||
* @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
|
||||
* @see org.springframework.test.context.event.EventPublishingTestExecutionListener
|
||||
* @see org.springframework.test.context.bean.override.mockito.MockitoResetTestExecutionListener
|
||||
* @see org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
|
||||
*/
|
||||
@AliasFor("value")
|
||||
Class<? extends TestExecutionListener>[] listeners() default {};
|
||||
|
||||
@@ -37,11 +37,15 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
public class BeanOverrideTestExecutionListener extends AbstractTestExecutionListener {
|
||||
|
||||
/**
|
||||
* Executes almost last ({@code LOWEST_PRECEDENCE - 50}).
|
||||
* Returns {@code 1950}, which ensures that the {@code BeanOverrideTestExecutionListener}
|
||||
* is ordered after the
|
||||
* {@link org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener
|
||||
* DirtiesContextBeforeModesTestExecutionListener} and just before the
|
||||
* {@link DependencyInjectionTestExecutionListener}.
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return LOWEST_PRECEDENCE - 50;
|
||||
return 1950;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class MockitoResetTestExecutionListener extends AbstractTestExecutionListener {
|
||||
|
||||
static final boolean mockitoPresent = ClassUtils.isPresent("org.mockito.Mockito",
|
||||
private static final boolean mockitoPresent = ClassUtils.isPresent("org.mockito.Mockito",
|
||||
MockitoResetTestExecutionListener.class.getClassLoader());
|
||||
|
||||
private static final String SPRING_MOCKITO_PACKAGE = "org.springframework.test.context.bean.override.mockito";
|
||||
@@ -62,8 +62,9 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
|
||||
private static final Predicate<MergedAnnotation<?>> isSpringMockitoAnnotation = mergedAnnotation ->
|
||||
mergedAnnotation.getType().getPackageName().equals(SPRING_MOCKITO_PACKAGE);
|
||||
|
||||
|
||||
/**
|
||||
* Executes before {@link org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener}.
|
||||
* Returns {@code Ordered.LOWEST_PRECEDENCE - 100}.
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
|
||||
Reference in New Issue
Block a user