Skip to content

Commit f68130d

Browse files
committed
Update Javadoc for @⁠TestBean support
See gh-32943
1 parent 42ace2c commit f68130d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBean.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
*
3737
* <p>The instance is created from a zero-argument static factory method in the
3838
* test class whose return type is compatible with the annotated field. In the
39-
* case of a nested test, any enclosing class it might have is also considered.
40-
* Similarly, in case the test class inherits from a base class the whole class
41-
* hierarchy is considered. The method is deduced as follows.
39+
* case of a nested test class, the enclosing class is also considered. Similarly,
40+
* if the test class extends from a base class or implements any interfaces, the
41+
* entire type hierarchy is considered. The method is deduced as follows.
4242
* <ul>
4343
* <li>If the {@link #methodName()} is specified, look for a static method with
4444
* that name.</li>

spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessor.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,29 @@
5353
class TestBeanOverrideProcessor implements BeanOverrideProcessor {
5454

5555
/**
56-
* Find a test bean factory {@link Method} in the given {@link Class} or one
57-
* of its parent classes.
56+
* Find a test bean factory {@link Method} for the given {@link Class}.
5857
* <p>Delegates to {@link #findTestBeanFactoryMethod(Class, Class, List)}.
5958
*/
6059
static Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, String... methodNames) {
6160
return findTestBeanFactoryMethod(clazz, methodReturnType, List.of(methodNames));
6261
}
6362

6463
/**
65-
* Find a test bean factory {@link Method} in the given {@link Class} or one
66-
* of its parent classes, which meets the following criteria.
64+
* Find a test bean factory {@link Method} for the given {@link Class}, which
65+
* meets the following criteria.
6766
* <ul>
6867
* <li>The method is static.</li>
6968
* <li>The method does not accept any arguments.</li>
7069
* <li>The method's return type matches the supplied {@code methodReturnType}.</li>
7170
* <li>The method's name is one of the supplied {@code methodNames}.</li>
7271
* </ul>
73-
* <p>If the test class inherits from another class, the class hierarchy is
74-
* searched for factory methods. Matching factory methods are prioritized
75-
* from closest to farthest from the test class in the class hierarchy,
76-
* provided they have the same name. However, if multiple methods are found
77-
* that match distinct candidate names, an exception is thrown.
72+
* <p>This method traverses up the type hierarchy of the given class in search
73+
* of the factory method, beginning with the class itself and then searching
74+
* implemented interfaces and superclasses. If a factory method is not found
75+
* in the type hierarchy, this method will also search on the enclosing class
76+
* if the class is a nested class.
77+
* <p>If multiple factory methods are found that match the search criteria,
78+
* an exception is thrown.
7879
* @param clazz the class in which to search for the factory method
7980
* @param methodReturnType the return type for the factory method
8081
* @param methodNames a set of supported names for the factory method

0 commit comments

Comments
 (0)