Update Javadoc for @⁠TestBean support

See gh-32943
This commit is contained in:
Sam Brannen 2024-06-03 17:17:51 +02:00
parent 42ace2c2c9
commit f68130d2e5
2 changed files with 13 additions and 12 deletions

View File

@ -36,9 +36,9 @@ import org.springframework.test.context.bean.override.BeanOverride;
*
* <p>The instance is created from a zero-argument static factory method in the
* test class whose return type is compatible with the annotated field. In the
* case of a nested test, any enclosing class it might have is also considered.
* Similarly, in case the test class inherits from a base class the whole class
* hierarchy is considered. The method is deduced as follows.
* case of a nested test class, the enclosing class is also considered. Similarly,
* if the test class extends from a base class or implements any interfaces, the
* entire type hierarchy is considered. The method is deduced as follows.
* <ul>
* <li>If the {@link #methodName()} is specified, look for a static method with
* that name.</li>

View File

@ -53,8 +53,7 @@ import org.springframework.util.StringUtils;
class TestBeanOverrideProcessor implements BeanOverrideProcessor {
/**
* Find a test bean factory {@link Method} in the given {@link Class} or one
* of its parent classes.
* Find a test bean factory {@link Method} for the given {@link Class}.
* <p>Delegates to {@link #findTestBeanFactoryMethod(Class, Class, List)}.
*/
static Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, String... methodNames) {
@ -62,19 +61,21 @@ class TestBeanOverrideProcessor implements BeanOverrideProcessor {
}
/**
* Find a test bean factory {@link Method} in the given {@link Class} or one
* of its parent classes, which meets the following criteria.
* Find a test bean factory {@link Method} for the given {@link Class}, which
* meets the following criteria.
* <ul>
* <li>The method is static.</li>
* <li>The method does not accept any arguments.</li>
* <li>The method's return type matches the supplied {@code methodReturnType}.</li>
* <li>The method's name is one of the supplied {@code methodNames}.</li>
* </ul>
* <p>If the test class inherits from another class, the class hierarchy is
* searched for factory methods. Matching factory methods are prioritized
* from closest to farthest from the test class in the class hierarchy,
* provided they have the same name. However, if multiple methods are found
* that match distinct candidate names, an exception is thrown.
* <p>This method traverses up the type hierarchy of the given class in search
* of the factory method, beginning with the class itself and then searching
* implemented interfaces and superclasses. If a factory method is not found
* in the type hierarchy, this method will also search on the enclosing class
* if the class is a nested class.
* <p>If multiple factory methods are found that match the search criteria,
* an exception is thrown.
* @param clazz the class in which to search for the factory method
* @param methodReturnType the return type for the factory method
* @param methodNames a set of supported names for the factory method