File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
spring-boot-project/spring-boot-test/src
main/java/org/springframework/boot/test/mock/mockito
test/java/org/springframework/boot/test/mock/mockito Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -252,11 +252,12 @@ private Set<String> getExistingBeans(ConfigurableListableBeanFactory beanFactory
252
252
Set <String > beans = new LinkedHashSet <>(
253
253
Arrays .asList (beanFactory .getBeanNamesForType (resolvableType , true , false )));
254
254
Class <?> type = resolvableType .resolve (Object .class );
255
+ String typeName = type .getName ();
255
256
for (String beanName : beanFactory .getBeanNamesForType (FactoryBean .class , true , false )) {
256
257
beanName = BeanFactoryUtils .transformedBeanName (beanName );
257
258
BeanDefinition beanDefinition = beanFactory .getBeanDefinition (beanName );
258
259
Object attribute = beanDefinition .getAttribute (FactoryBean .OBJECT_TYPE_ATTRIBUTE );
259
- if (resolvableType .equals (attribute ) || type .equals (attribute )) {
260
+ if (resolvableType .equals (attribute ) || type .equals (attribute ) || typeName . equals ( attribute ) ) {
260
261
beans .add (beanName );
261
262
}
262
263
}
Original file line number Diff line number Diff line change @@ -73,6 +73,18 @@ void cannotMockMultipleQualifiedBeans() {
73
73
+ " expected a single matching bean to replace but found [example1, example3]" );
74
74
}
75
75
76
+ @ Test
77
+ void canMockBeanProducedByFactoryBeanWithStringObjectTypeAttribute () {
78
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
79
+ MockitoPostProcessor .register (context );
80
+ RootBeanDefinition factoryBeanDefinition = new RootBeanDefinition (TestFactoryBean .class );
81
+ factoryBeanDefinition .setAttribute (FactoryBean .OBJECT_TYPE_ATTRIBUTE , SomeInterface .class .getName ());
82
+ context .registerBeanDefinition ("beanToBeMocked" , factoryBeanDefinition );
83
+ context .register (MockedFactoryBean .class );
84
+ context .refresh ();
85
+ assertThat (Mockito .mockingDetails (context .getBean ("beanToBeMocked" )).isMock ()).isTrue ();
86
+ }
87
+
76
88
@ Test
77
89
void canMockBeanProducedByFactoryBeanWithClassObjectTypeAttribute () {
78
90
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
You can’t perform that action at this time.
0 commit comments