diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java index 2d0fd021deb..f1f4fbf81c8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java @@ -54,7 +54,7 @@ class BeanOverrideContextCustomizerFactory implements ContextCustomizerFactory { } private void findBeanOverrideHandlers(Class testClass, @Nullable String contextName, Set handlers) { - BeanOverrideHandler.findAllHandlers(testClass).stream() + BeanOverrideUtils.findAllHandlers(testClass).stream() // If a handler does not specify a context name, it always gets applied. // Otherwise, the handler's context name must match the current context name. .filter(handler -> handler.getContextName().isEmpty() || handler.getContextName().equals(contextName)) diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java index 259420163fc..13b3fc5a9c2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java @@ -17,33 +17,20 @@ package org.springframework.test.context.bean.override; import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.BiConsumer; import org.jspecify.annotations.Nullable; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.SingletonBeanRegistry; import org.springframework.core.ResolvableType; -import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.style.ToStringCreator; -import org.springframework.test.context.TestContextAnnotationUtils; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -import static org.springframework.core.annotation.MergedAnnotations.SearchStrategy.DIRECT; /** * Handler for Bean Override injection points that is responsible for creating @@ -90,10 +77,6 @@ import static org.springframework.core.annotation.MergedAnnotations.SearchStrate */ public abstract class BeanOverrideHandler { - private static final Comparator> reversedMetaDistance = - Comparator.> comparingInt(MergedAnnotation::getDistance).reversed(); - - private final @Nullable Field field; private final Set qualifierAnnotations; @@ -153,6 +136,7 @@ public abstract class BeanOverrideHandler { this.contextName = contextName; } + /** * Process the given {@code testClass} and build the corresponding * {@code BeanOverrideHandler} list derived from {@link BeanOverride @BeanOverride} @@ -161,111 +145,13 @@ public abstract class BeanOverrideHandler { * search for {@code @BeanOverride} declarations on classes or interfaces. * @param testClass the test class to process * @return a list of bean override handlers - * @see #findAllHandlers(Class) + * @see BeanOverrideUtils + * @deprecated As of Spring Framework 7.1, in favor of + * {@link BeanOverrideUtils#findHandlersForFields(Class)} */ + @Deprecated(since = "7.1", forRemoval = true) public static List forTestClass(Class testClass) { - return findHandlers(testClass, true); - } - - /** - * Process the given {@code testClass} and build the corresponding - * {@code BeanOverrideHandler} list derived from {@link BeanOverride @BeanOverride} - * fields in the test class and in its type hierarchy as well as from - * {@code @BeanOverride} declarations on classes and interfaces. - *

This method additionally searches for {@code @BeanOverride} declarations - * in the enclosing class hierarchy based on - * {@link TestContextAnnotationUtils#searchEnclosingClass(Class)} semantics. - * @param testClass the test class to process - * @return a list of bean override handlers - * @since 6.2.2 - */ - static List findAllHandlers(Class testClass) { - return findHandlers(testClass, false); - } - - private static List findHandlers(Class testClass, boolean localFieldsOnly) { - List handlers = new ArrayList<>(); - findHandlers(testClass, testClass, handlers, localFieldsOnly, new HashSet<>()); - return handlers; - } - - /** - * Find handlers using tail recursion to ensure that "locally declared" bean overrides - * take precedence over inherited bean overrides. - *

Note: the search algorithm is effectively the inverse of the algorithm used in - * {@link org.springframework.test.context.TestContextAnnotationUtils#findAnnotationDescriptor(Class, Class)}, - * but with tail recursion the semantics should be the same. - * @param clazz the class in/on which to search - * @param testClass the original test class - * @param handlers the list of handlers found - * @param localFieldsOnly whether to search only on local fields within the type hierarchy - * @param visitedTypes the set of types already visited - * @since 6.2.2 - */ - private static void findHandlers(Class clazz, Class testClass, List handlers, - boolean localFieldsOnly, Set> visitedTypes) { - - // 0) Ensure that we do not process the same class or interface multiple times. - if (!visitedTypes.add(clazz)) { - return; - } - - // 1) Search enclosing class hierarchy. - if (!localFieldsOnly && TestContextAnnotationUtils.searchEnclosingClass(clazz)) { - findHandlers(clazz.getEnclosingClass(), testClass, handlers, localFieldsOnly, visitedTypes); - } - - // 2) Search class hierarchy. - Class superclass = clazz.getSuperclass(); - if (superclass != null && superclass != Object.class) { - findHandlers(superclass, testClass, handlers, localFieldsOnly, visitedTypes); - } - - if (!localFieldsOnly) { - // 3) Search interfaces. - for (Class ifc : clazz.getInterfaces()) { - findHandlers(ifc, testClass, handlers, localFieldsOnly, visitedTypes); - } - - // 4) Process current class. - processClass(clazz, testClass, handlers); - } - - // 5) Process fields in current class. - ReflectionUtils.doWithLocalFields(clazz, field -> processField(field, testClass, handlers)); - } - - private static void processClass(Class clazz, Class testClass, List handlers) { - processElement(clazz, testClass, (processor, composedAnnotation) -> - processor.createHandlers(composedAnnotation, testClass).forEach(handlers::add)); - } - - private static void processField(Field field, Class testClass, List handlers) { - AtomicBoolean overrideAnnotationFound = new AtomicBoolean(); - processElement(field, testClass, (processor, composedAnnotation) -> { - Assert.state(!Modifier.isStatic(field.getModifiers()), - () -> "@BeanOverride field must not be static: " + field); - Assert.state(overrideAnnotationFound.compareAndSet(false, true), - () -> "Multiple @BeanOverride annotations found on field: " + field); - handlers.add(processor.createHandler(composedAnnotation, testClass, field)); - }); - } - - private static void processElement(AnnotatedElement element, Class testClass, - BiConsumer consumer) { - - MergedAnnotations.from(element, DIRECT) - .stream(BeanOverride.class) - .sorted(reversedMetaDistance) - .forEach(mergedAnnotation -> { - MergedAnnotation metaSource = mergedAnnotation.getMetaSource(); - Assert.state(metaSource != null, "@BeanOverride annotation must be meta-present"); - - BeanOverride beanOverride = mergedAnnotation.synthesize(); - BeanOverrideProcessor processor = BeanUtils.instantiateClass(beanOverride.value()); - Annotation composedAnnotation = metaSource.synthesize(); - consumer.accept(processor, composedAnnotation); - }); + return BeanOverrideUtils.findHandlersForFields(testClass); } diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java index 229fdb21553..6836cf2392b 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideTestExecutionListener.java @@ -102,7 +102,7 @@ public class BeanOverrideTestExecutionListener extends AbstractTestExecutionList // test instance as the "test class". Class testClass = testInstance.getClass(); - List handlers = BeanOverrideHandler.forTestClass(testClass); + List handlers = BeanOverrideUtils.findHandlersForFields(testClass); if (!handlers.isEmpty()) { ApplicationContext applicationContext = testContext.getApplicationContext(); diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideUtils.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideUtils.java new file mode 100644 index 00000000000..c833a004bd4 --- /dev/null +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideUtils.java @@ -0,0 +1,169 @@ +/* + * Copyright 2002-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.bean.override; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiConsumer; + +import org.springframework.beans.BeanUtils; +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.core.annotation.MergedAnnotations; +import org.springframework.test.context.TestContextAnnotationUtils; +import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; + +import static org.springframework.core.annotation.MergedAnnotations.SearchStrategy.DIRECT; + +/** + * Utility methods for working with bean overrides. + * + *

Primarily intended for use within the framework. + * + * @author Sam Brannen + * @since 7.1 + */ +public abstract class BeanOverrideUtils { + + private static final Comparator> reversedMetaDistance = + Comparator.> comparingInt(MergedAnnotation::getDistance).reversed(); + + + /** + * Process the given {@code testClass} and build the corresponding + * {@link BeanOverrideHandler} list derived from {@link BeanOverride @BeanOverride} + * fields in the test class and its type hierarchy. + *

This method does not search the enclosing class hierarchy and does not + * search for {@code @BeanOverride} declarations on classes or interfaces. + * @param testClass the test class to process + * @return a list of bean override handlers + * @see #findAllHandlers(Class) + */ + public static List findHandlersForFields(Class testClass) { + return findHandlers(testClass, true); + } + + /** + * Process the given {@code testClass} and build the corresponding + * {@link BeanOverrideHandler} list derived from {@link BeanOverride @BeanOverride} + * fields in the test class and in its type hierarchy as well as from + * {@code @BeanOverride} declarations on classes and interfaces. + *

This method additionally searches for {@code @BeanOverride} declarations + * in the enclosing class hierarchy based on + * {@link TestContextAnnotationUtils#searchEnclosingClass(Class)} semantics. + * @param testClass the test class to process + * @return a list of bean override handlers + * @see #findHandlersForFields(Class) + */ + public static List findAllHandlers(Class testClass) { + return findHandlers(testClass, false); + } + + private static List findHandlers(Class testClass, boolean localFieldsOnly) { + List handlers = new ArrayList<>(); + findHandlers(testClass, testClass, handlers, localFieldsOnly, new HashSet<>()); + return handlers; + } + + /** + * Find handlers using tail recursion to ensure that "locally declared" bean overrides + * take precedence over inherited bean overrides. + *

Note: the search algorithm is effectively the inverse of the algorithm used in + * {@link org.springframework.test.context.TestContextAnnotationUtils#findAnnotationDescriptor(Class, Class)}, + * but with tail recursion the semantics should be the same. + * @param clazz the class in/on which to search + * @param testClass the original test class + * @param handlers the list of handlers found + * @param localFieldsOnly whether to search only on local fields within the type hierarchy + * @param visitedTypes the set of types already visited + * @since 6.2.2 + */ + private static void findHandlers(Class clazz, Class testClass, List handlers, + boolean localFieldsOnly, Set> visitedTypes) { + + // 0) Ensure that we do not process the same class or interface multiple times. + if (!visitedTypes.add(clazz)) { + return; + } + + // 1) Search enclosing class hierarchy. + if (!localFieldsOnly && TestContextAnnotationUtils.searchEnclosingClass(clazz)) { + findHandlers(clazz.getEnclosingClass(), testClass, handlers, localFieldsOnly, visitedTypes); + } + + // 2) Search class hierarchy. + Class superclass = clazz.getSuperclass(); + if (superclass != null && superclass != Object.class) { + findHandlers(superclass, testClass, handlers, localFieldsOnly, visitedTypes); + } + + if (!localFieldsOnly) { + // 3) Search interfaces. + for (Class ifc : clazz.getInterfaces()) { + findHandlers(ifc, testClass, handlers, localFieldsOnly, visitedTypes); + } + + // 4) Process current class. + processClass(clazz, testClass, handlers); + } + + // 5) Process fields in current class. + ReflectionUtils.doWithLocalFields(clazz, field -> processField(field, testClass, handlers)); + } + + private static void processClass(Class clazz, Class testClass, List handlers) { + processElement(clazz, testClass, (processor, composedAnnotation) -> + processor.createHandlers(composedAnnotation, testClass).forEach(handlers::add)); + } + + private static void processField(Field field, Class testClass, List handlers) { + AtomicBoolean overrideAnnotationFound = new AtomicBoolean(); + processElement(field, testClass, (processor, composedAnnotation) -> { + Assert.state(!Modifier.isStatic(field.getModifiers()), + () -> "@BeanOverride field must not be static: " + field); + Assert.state(overrideAnnotationFound.compareAndSet(false, true), + () -> "Multiple @BeanOverride annotations found on field: " + field); + handlers.add(processor.createHandler(composedAnnotation, testClass, field)); + }); + } + + private static void processElement(AnnotatedElement element, Class testClass, + BiConsumer consumer) { + + MergedAnnotations.from(element, DIRECT) + .stream(BeanOverride.class) + .sorted(reversedMetaDistance) + .forEach(mergedAnnotation -> { + MergedAnnotation metaSource = mergedAnnotation.getMetaSource(); + Assert.state(metaSource != null, "@BeanOverride annotation must be meta-present"); + + BeanOverride beanOverride = mergedAnnotation.synthesize(); + BeanOverrideProcessor processor = BeanUtils.instantiateClass(beanOverride.value()); + Annotation composedAnnotation = metaSource.synthesize(); + consumer.accept(processor, composedAnnotation); + }); + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java index 4a1dd92774f..7eda38045ba 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessorTests.java @@ -401,7 +401,7 @@ class BeanOverrideBeanFactoryPostProcessorTests { private static AnnotationConfigApplicationContext createContext(Class testClass) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - Set handlers = new LinkedHashSet<>(BeanOverrideTestUtils.findHandlers(testClass)); + Set handlers = new LinkedHashSet<>(BeanOverrideUtils.findHandlersForFields(testClass)); new BeanOverrideContextCustomizer(handlers).customizeContext(context, mock(MergedContextConfiguration.class)); return context; } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java index 12656bbe149..b343f619333 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java @@ -51,14 +51,14 @@ class BeanOverrideHandlerTests { @Test void forTestClassWithSingleField() { - List handlers = BeanOverrideTestUtils.findHandlers(SingleAnnotation.class); + List handlers = BeanOverrideUtils.findHandlersForFields(SingleAnnotation.class); assertThat(handlers).singleElement().satisfies(hasBeanOverrideHandler( field(SingleAnnotation.class, "message"), String.class, null)); } @Test void forTestClassWithMultipleFields() { - List handlers = BeanOverrideTestUtils.findHandlers(MultipleAnnotations.class); + List handlers = BeanOverrideUtils.findHandlersForFields(MultipleAnnotations.class); assertThat(handlers).hasSize(2) .anySatisfy(hasBeanOverrideHandler( field(MultipleAnnotations.class, "message"), String.class, null)) @@ -68,7 +68,7 @@ class BeanOverrideHandlerTests { @Test void forTestClassWithMultipleFieldsWithIdenticalMetadata() { - List handlers = BeanOverrideTestUtils.findHandlers(MultipleAnnotationsDuplicate.class); + List handlers = BeanOverrideUtils.findHandlersForFields(MultipleAnnotationsDuplicate.class); assertThat(handlers).hasSize(2) .anySatisfy(hasBeanOverrideHandler( field(MultipleAnnotationsDuplicate.class, "message1"), String.class, "messageBean")) @@ -81,7 +81,7 @@ class BeanOverrideHandlerTests { void forTestClassWithCompetingBeanOverrideAnnotationsOnSameField() { Field faultyField = field(MultipleAnnotationsOnSameField.class, "message"); assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideTestUtils.findHandlers(MultipleAnnotationsOnSameField.class)) + .isThrownBy(() -> BeanOverrideUtils.findHandlersForFields(MultipleAnnotationsOnSameField.class)) .withMessageStartingWith("Multiple @BeanOverride annotations found") .withMessageContaining(faultyField.toString()); } @@ -90,7 +90,7 @@ class BeanOverrideHandlerTests { void forTestClassWithStaticBeanOverrideField() { Field staticField = field(StaticBeanOverrideField.class, "message"); assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideTestUtils.findHandlers(StaticBeanOverrideField.class)) + .isThrownBy(() -> BeanOverrideUtils.findHandlersForFields(StaticBeanOverrideField.class)) .withMessage("@BeanOverride field must not be static: " + staticField); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideTestUtils.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideTestUtils.java deleted file mode 100644 index added7402c5..00000000000 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideTestUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.test.context.bean.override; - -import java.util.List; - -/** - * Test utilities for Bean Overrides. - * - * @author Sam Brannen - * @since 6.2.2 - */ -public abstract class BeanOverrideTestUtils { - - public static List findHandlers(Class testClass) { - return BeanOverrideHandler.forTestClass(testClass); - } - - public static List findAllHandlers(Class testClass) { - return BeanOverrideHandler.findAllHandlers(testClass); - } - -} diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandlerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandlerTests.java index 778adb05246..3fd8ff6fdbb 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandlerTests.java @@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.ResolvableType; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.BeanOverrideStrategy; -import org.springframework.test.context.bean.override.BeanOverrideTestUtils; +import org.springframework.test.context.bean.override.BeanOverrideUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -44,20 +44,20 @@ class TestBeanOverrideHandlerTests { @Test void beanNameIsSetToNullIfAnnotationNameIsEmpty() { - List handlers = BeanOverrideTestUtils.findHandlers(SampleOneOverride.class); + List handlers = BeanOverrideUtils.findHandlersForFields(SampleOneOverride.class); assertThat(handlers).singleElement().extracting(BeanOverrideHandler::getBeanName).isNull(); } @Test void beanNameIsSetToAnnotationName() { - List handlers = BeanOverrideTestUtils.findHandlers(SampleOneOverrideWithName.class); + List handlers = BeanOverrideUtils.findHandlersForFields(SampleOneOverrideWithName.class); assertThat(handlers).singleElement().extracting(BeanOverrideHandler::getBeanName).isEqualTo("anotherBean"); } @Test void failsWithMissingMethod() { assertThatIllegalStateException() - .isThrownBy(() -> BeanOverrideTestUtils.findHandlers(SampleMissingMethod.class)) + .isThrownBy(() -> BeanOverrideUtils.findHandlersForFields(SampleMissingMethod.class)) .withMessage("No static method found named message() in %s with return type %s", SampleMissingMethod.class.getName(), String.class.getName()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandlerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandlerTests.java index 876e2fbacaa..3fe2c80157a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandlerTests.java @@ -26,7 +26,7 @@ import org.mockito.Answers; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.bean.override.BeanOverrideHandler; -import org.springframework.test.context.bean.override.BeanOverrideTestUtils; +import org.springframework.test.context.bean.override.BeanOverrideUtils; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -42,13 +42,13 @@ class MockitoBeanOverrideHandlerTests { @Test void beanNameIsSetToNullIfAnnotationNameIsEmpty() { - List list = BeanOverrideTestUtils.findHandlers(SampleOneMock.class); + List list = BeanOverrideUtils.findHandlersForFields(SampleOneMock.class); assertThat(list).singleElement().satisfies(handler -> assertThat(handler.getBeanName()).isNull()); } @Test void beanNameIsSetToAnnotationName() { - List list = BeanOverrideTestUtils.findHandlers(SampleOneMockWithName.class); + List list = BeanOverrideUtils.findHandlersForFields(SampleOneMockWithName.class); assertThat(list).singleElement().satisfies(handler -> assertThat(handler.getBeanName()).isEqualTo("anotherService")); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandlerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandlerTests.java index 9867a276453..98f4619fd54 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandlerTests.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.bean.override.BeanOverrideHandler; -import org.springframework.test.context.bean.override.BeanOverrideTestUtils; +import org.springframework.test.context.bean.override.BeanOverrideUtils; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -38,13 +38,13 @@ class MockitoSpyBeanOverrideHandlerTests { @Test void beanNameIsSetToNullIfAnnotationNameIsEmpty() { - List list = BeanOverrideTestUtils.findHandlers(SampleOneSpy.class); + List list = BeanOverrideUtils.findHandlersForFields(SampleOneSpy.class); assertThat(list).singleElement().satisfies(handler -> assertThat(handler.getBeanName()).isNull()); } @Test void beanNameIsSetToAnnotationName() { - List list = BeanOverrideTestUtils.findHandlers(SampleOneSpyWithName.class); + List list = BeanOverrideUtils.findHandlersForFields(SampleOneSpyWithName.class); assertThat(list).singleElement().satisfies(handler -> assertThat(handler.getBeanName()).isEqualTo("anotherService")); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoBeansTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoBeansTests.java index 2f30d8a7515..b7714e3e512 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoBeansTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoBeansTests.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test; import org.springframework.core.ResolvableType; import org.springframework.test.context.bean.override.BeanOverrideHandler; -import org.springframework.test.context.bean.override.BeanOverrideTestUtils; +import org.springframework.test.context.bean.override.BeanOverrideUtils; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.bean.override.mockito.MockitoBeans; @@ -59,7 +59,7 @@ class MockitoBeansTests { private static Stream> getRegisteredMockTypes(Class testClass) { - return BeanOverrideTestUtils.findAllHandlers(testClass) + return BeanOverrideUtils.findAllHandlers(testClass) .stream() .map(BeanOverrideHandler::getBeanType) .map(ResolvableType::getRawClass); diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoSpyBeansTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoSpyBeansTests.java index 181cc082e4e..738211e48b9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoSpyBeansTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/typelevel/MockitoSpyBeansTests.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test; import org.springframework.core.ResolvableType; import org.springframework.test.context.bean.override.BeanOverrideHandler; -import org.springframework.test.context.bean.override.BeanOverrideTestUtils; +import org.springframework.test.context.bean.override.BeanOverrideUtils; import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.bean.override.mockito.MockitoSpyBeans; @@ -59,7 +59,7 @@ class MockitoSpyBeansTests { private static Stream> getRegisteredMockTypes(Class testClass) { - return BeanOverrideTestUtils.findAllHandlers(testClass) + return BeanOverrideUtils.findAllHandlers(testClass) .stream() .map(BeanOverrideHandler::getBeanType) .map(ResolvableType::getRawClass);