From ea8b18fbc778ab1780790ffc8ecfca8af59c13f0 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:41:08 +0100 Subject: [PATCH] Polish Javadoc for BeanOverrideHandler --- .../override/BeanOverrideContextCustomizerFactory.java | 6 +++--- .../test/context/bean/override/BeanOverrideHandler.java | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) 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 544b43e996b6..e5d66ba8b0d3 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 @@ -44,16 +44,16 @@ public BeanOverrideContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { Set handlers = new LinkedHashSet<>(); - findBeanOverrideHandler(testClass, handlers); + findBeanOverrideHandlers(testClass, handlers); if (handlers.isEmpty()) { return null; } return new BeanOverrideContextCustomizer(handlers); } - private void findBeanOverrideHandler(Class testClass, Set handlers) { + private void findBeanOverrideHandlers(Class testClass, Set handlers) { if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) { - findBeanOverrideHandler(testClass.getEnclosingClass(), handlers); + findBeanOverrideHandlers(testClass.getEnclosingClass(), handlers); } BeanOverrideHandler.forTestClass(testClass).forEach(handler -> Assert.state(handlers.add(handler), () -> 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 b0f6c0f56dd4..b11081392009 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 @@ -51,7 +51,9 @@ * unique set of metadata used to identify the bean to override. Overridden * {@code equals()} and {@code hashCode()} methods should also delegate to the * {@code super} implementations in this class in order to support the basic - * metadata used by all bean overrides. + * metadata used by all bean overrides. In addition, it is recommended that + * implementations override {@code toString()} to include all relevant metadata + * in order to enhance diagnostics. * *

Concrete implementations of {@code BeanOverrideHandler} can store additional * metadata to use during override {@linkplain #createOverrideInstance instance @@ -93,9 +95,11 @@ protected BeanOverrideHandler(Field field, ResolvableType beanType, @Nullable St /** * Process the given {@code testClass} and build the corresponding * {@code BeanOverrideHandler} list derived from {@link BeanOverride @BeanOverride} - * fields in the test class, its type hierarchy, and its enclosing class hierarchy. + * fields in the test class and its type hierarchy. + *

This method does not search the enclosing class hierarchy. * @param testClass the test class to process * @return a list of bean override handlers + * @see org.springframework.test.context.TestContextAnnotationUtils#searchEnclosingClass(Class) */ public static List forTestClass(Class testClass) { List handlers = new LinkedList<>();