Check for Class and ResolvableType object type attributes

See gh-36224
This commit is contained in:
Bernardo Bulgarelli
2023-07-04 22:28:02 -03:00
committed by Andy Wilkinson
parent fe08c70973
commit 3a7185206e
2 changed files with 38 additions and 1 deletions

View File

@@ -254,7 +254,18 @@ public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
beanName = BeanFactoryUtils.transformedBeanName(beanName);
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
if (typeName.equals(beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE))) {
Object attribute = beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
if(attribute instanceof Class) {
Class<?> attributeClass = (Class<?>) attribute;
if (typeName.equals(attributeClass.getName())) {
beans.add(beanName);
}
} else if (attribute instanceof ResolvableType) {
ResolvableType resolvableType = (ResolvableType) attribute;
if (typeName.equals(resolvableType.resolve(Object.class).getName())) {
beans.add(beanName);
}
} else if (typeName.equals(attribute)){
beans.add(beanName);
}
}