mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Remove invalid check for String-based FactoryBean.OBJECT_TYPE_ATTRIBUTE
Closes gh-36659
This commit is contained in:
parent
b46e81c230
commit
421448233f
@ -252,12 +252,11 @@ public class MockitoPostProcessor implements InstantiationAwareBeanPostProcessor
|
|||||||
Set<String> beans = new LinkedHashSet<>(
|
Set<String> beans = new LinkedHashSet<>(
|
||||||
Arrays.asList(beanFactory.getBeanNamesForType(resolvableType, true, false)));
|
Arrays.asList(beanFactory.getBeanNamesForType(resolvableType, true, false)));
|
||||||
Class<?> type = resolvableType.resolve(Object.class);
|
Class<?> type = resolvableType.resolve(Object.class);
|
||||||
String typeName = type.getName();
|
|
||||||
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
|
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
|
||||||
beanName = BeanFactoryUtils.transformedBeanName(beanName);
|
beanName = BeanFactoryUtils.transformedBeanName(beanName);
|
||||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||||
Object attribute = beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
|
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);
|
beans.add(beanName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,18 +73,6 @@ class MockitoPostProcessorTests {
|
|||||||
+ " expected a single matching bean to replace but found [example1, example3]");
|
+ " 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
|
@Test
|
||||||
void canMockBeanProducedByFactoryBeanWithClassObjectTypeAttribute() {
|
void canMockBeanProducedByFactoryBeanWithClassObjectTypeAttribute() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
Loading…
Reference in New Issue
Block a user