Find unique @TestBean factory methods in class hierarchy
I accidentally introduced a regression in commit d185bb1d97 by no
longer checking the number of unique method names found when searching
for @TestBean factory methods.
This commit reintroduces that check and introduces a proper unit test
in TestBeanOverrideProcessorTests.
It turns out that we already had an integration test that was intended
to check for this scenario; however, that test actually did not test
this scenario due to a copy-and-paste error. Thus, this commit also
updates TestBeanInheritanceIntegrationTests so that
fieldInSupertypeWithPrioritizedFactoryMethodInSubtype() tests what it's
supposed to.
This commit is contained in:
@@ -92,16 +92,16 @@ class TestBeanOverrideProcessor implements BeanOverrideProcessor {
|
||||
|
||||
Set<Method> methods = findMethods(clazz, methodFilter);
|
||||
|
||||
int methodCount = methods.size();
|
||||
Assert.state(methodCount > 0, () -> """
|
||||
Assert.state(!methods.isEmpty(), () -> """
|
||||
Failed to find a static test bean factory method in %s with return type %s \
|
||||
whose name matches one of the supported candidates %s""".formatted(
|
||||
clazz.getName(), methodReturnType.getName(), supportedNames));
|
||||
|
||||
Assert.state(methodCount == 1, () -> """
|
||||
long uniqueMethodNameCount = methods.stream().map(Method::getName).distinct().count();
|
||||
Assert.state(uniqueMethodNameCount == 1, () -> """
|
||||
Found %d competing static test bean factory methods in %s with return type %s \
|
||||
whose name matches one of the supported candidates %s""".formatted(
|
||||
methodCount, clazz.getName(), methodReturnType.getName(), supportedNames));
|
||||
uniqueMethodNameCount, clazz.getName(), methodReturnType.getName(), supportedNames));
|
||||
|
||||
return methods.iterator().next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user