Skip to content

Commit

Permalink
Remove invalid check for String-based FactoryBean.OBJECT_TYPE_ATTRIBUTE
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Aug 3, 2023
1 parent 98b5ac6 commit 780dfe3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,11 @@ private Set<String> getExistingBeans(ConfigurableListableBeanFactory beanFactory
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ void cannotMockMultipleQualifiedBeans() {
+ " 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();
Expand Down

0 comments on commit 780dfe3

Please sign in to comment.