mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +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<>(
|
||||
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…
Reference in New Issue
Block a user