Remove invalid check for String-based FactoryBean.OBJECT_TYPE_ATTRIBUTE

Closes gh-36659
pull/36455/head
Stephane Nicoll 1 year ago
parent b46e81c230
commit 421448233f

@ -252,12 +252,11 @@ public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor
Set<String> beans = new LinkedHashSet<>(
Arrays.asList(beanFactory.getBeanNamesForType(resolvableType, true, false)));
Class<?> type = resolvableType.resolve(Object.class);
String typeName = type.getName();
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
beanName = BeanFactoryUtils.transformedBeanName(beanName);
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
Object attribute = beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
if (resolvableType.equals(attribute) || type.equals(attribute) || typeName.equals(attribute)) {
if (resolvableType.equals(attribute) || type.equals(attribute)) {
beans.add(beanName);
}
}

@ -73,18 +73,6 @@ class MockitoPostProcessorTests {
+ " expected a single matching bean to replace but found [example1, example3]");
}
@Test
void canMockBeanProducedByFactoryBeanWithStringObjectTypeAttribute() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
MockitoPostProcessor.register(context);
RootBeanDefinition factoryBeanDefinition = new RootBeanDefinition(TestFactoryBean.class);
factoryBeanDefinition.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, SomeInterface.class.getName());
context.registerBeanDefinition("beanToBeMocked", factoryBeanDefinition);
context.register(MockedFactoryBean.class);
context.refresh();
assertThat(Mockito.mockingDetails(context.getBean("beanToBeMocked")).isMock()).isTrue();
}
@Test
void canMockBeanProducedByFactoryBeanWithClassObjectTypeAttribute() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

Loading…
Cancel
Save