26
26
import java .security .PrivilegedAction ;
27
27
import java .text .NumberFormat ;
28
28
import java .text .ParseException ;
29
- import java .util .Arrays ;
30
29
import java .util .HashSet ;
31
30
import java .util .Iterator ;
32
31
import java .util .List ;
95
94
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
96
95
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
97
96
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
97
+ import static org .assertj .core .api .Assertions .assertThatNoException ;
98
98
import static org .mockito .ArgumentMatchers .any ;
99
99
import static org .mockito .ArgumentMatchers .eq ;
100
100
import static org .mockito .ArgumentMatchers .isNull ;
@@ -178,10 +178,8 @@ void prototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
178
178
registerBeanDefinitions (p );
179
179
180
180
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
181
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
182
- assertThat (beanNames ).hasSize (0 );
183
- beanNames = lbf .getBeanNamesForAnnotation (SuppressWarnings .class );
184
- assertThat (beanNames ).hasSize (0 );
181
+ assertBeanNamesForType (TestBean .class , false , false );
182
+ assertThat (lbf .getBeanNamesForAnnotation (SuppressWarnings .class )).isEmpty ();
185
183
186
184
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
187
185
assertThat (lbf .containsBean ("x1" )).isTrue ();
@@ -212,10 +210,8 @@ void singletonFactoryBeanIgnoredByNonEagerTypeMatching() {
212
210
registerBeanDefinitions (p );
213
211
214
212
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
215
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
216
- assertThat (beanNames ).hasSize (0 );
217
- beanNames = lbf .getBeanNamesForAnnotation (SuppressWarnings .class );
218
- assertThat (beanNames ).hasSize (0 );
213
+ assertBeanNamesForType (TestBean .class , false , false );
214
+ assertThat (lbf .getBeanNamesForAnnotation (SuppressWarnings .class )).isEmpty ();
219
215
220
216
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
221
217
assertThat (lbf .containsBean ("x1" )).isTrue ();
@@ -245,10 +241,8 @@ void nonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
245
241
registerBeanDefinitions (p );
246
242
247
243
assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
248
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
249
- assertThat (beanNames ).hasSize (0 );
250
- beanNames = lbf .getBeanNamesForAnnotation (SuppressWarnings .class );
251
- assertThat (beanNames ).hasSize (0 );
244
+ assertBeanNamesForType (TestBean .class , false , false );
245
+ assertThat (lbf .getBeanNamesForAnnotation (SuppressWarnings .class )).isEmpty ();
252
246
253
247
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
254
248
assertThat (lbf .containsBean ("x1" )).isTrue ();
@@ -278,10 +272,8 @@ void initializedFactoryBeanFoundByNonEagerTypeMatching() {
278
272
registerBeanDefinitions (p );
279
273
lbf .preInstantiateSingletons ();
280
274
281
- assertThat (!DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isTrue ();
282
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
283
- assertThat (beanNames ).hasSize (1 );
284
- assertThat (beanNames [0 ]).isEqualTo ("x1" );
275
+ assertThat (DummyFactory .wasPrototypeCreated ()).as ("prototype not instantiated" ).isFalse ();
276
+ assertBeanNamesForType (TestBean .class , true , false , "x1" );
285
277
assertThat (lbf .containsSingleton ("x1" )).isTrue ();
286
278
assertThat (lbf .containsBean ("x1" )).isTrue ();
287
279
assertThat (lbf .containsBean ("&x1" )).isTrue ();
@@ -316,14 +308,10 @@ void initializedFactoryBeanFoundByNonEagerTypeMatching() {
316
308
assertThat (lbf .isTypeMatch ("&x2" , Object .class )).isTrue ();
317
309
assertThat (lbf .getType ("x2" )).isEqualTo (TestBean .class );
318
310
assertThat (lbf .getType ("&x2" )).isEqualTo (DummyFactory .class );
319
- assertThat (lbf .getAliases ("x1" ).length ).isEqualTo (1 );
320
- assertThat (lbf .getAliases ("x1" )[0 ]).isEqualTo ("x2" );
321
- assertThat (lbf .getAliases ("&x1" ).length ).isEqualTo (1 );
322
- assertThat (lbf .getAliases ("&x1" )[0 ]).isEqualTo ("&x2" );
323
- assertThat (lbf .getAliases ("x2" ).length ).isEqualTo (1 );
324
- assertThat (lbf .getAliases ("x2" )[0 ]).isEqualTo ("x1" );
325
- assertThat (lbf .getAliases ("&x2" ).length ).isEqualTo (1 );
326
- assertThat (lbf .getAliases ("&x2" )[0 ]).isEqualTo ("&x1" );
311
+ assertThat (lbf .getAliases ("x1" )).containsExactly ("x2" );
312
+ assertThat (lbf .getAliases ("&x1" )).containsExactly ("&x2" );
313
+ assertThat (lbf .getAliases ("x2" )).containsExactly ("x1" );
314
+ assertThat (lbf .getAliases ("&x2" )).containsExactly ("&x1" );
327
315
}
328
316
329
317
@ Test
@@ -333,9 +321,7 @@ void staticFactoryMethodFoundByNonEagerTypeMatching() {
333
321
lbf .registerBeanDefinition ("x1" , rbd );
334
322
335
323
TestBeanFactory .initialized = false ;
336
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
337
- assertThat (beanNames ).hasSize (1 );
338
- assertThat (beanNames [0 ]).isEqualTo ("x1" );
324
+ assertBeanNamesForType (TestBean .class , true , false , "x1" );
339
325
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
340
326
assertThat (lbf .containsBean ("x1" )).isTrue ();
341
327
assertThat (lbf .containsBean ("&x1" )).isFalse ();
@@ -358,9 +344,7 @@ void staticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
358
344
lbf .registerBeanDefinition ("x1" , rbd );
359
345
360
346
TestBeanFactory .initialized = false ;
361
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
362
- assertThat (beanNames ).hasSize (1 );
363
- assertThat (beanNames [0 ]).isEqualTo ("x1" );
347
+ assertBeanNamesForType (TestBean .class , true , false , "x1" );
364
348
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
365
349
assertThat (lbf .containsBean ("x1" )).isTrue ();
366
350
assertThat (lbf .containsBean ("&x1" )).isFalse ();
@@ -385,9 +369,7 @@ void nonStaticFactoryMethodFoundByNonEagerTypeMatching() {
385
369
lbf .registerBeanDefinition ("x1" , rbd );
386
370
387
371
TestBeanFactory .initialized = false ;
388
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
389
- assertThat (beanNames ).hasSize (1 );
390
- assertThat (beanNames [0 ]).isEqualTo ("x1" );
372
+ assertBeanNamesForType (TestBean .class , true , false , "x1" );
391
373
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
392
374
assertThat (lbf .containsBean ("x1" )).isTrue ();
393
375
assertThat (lbf .containsBean ("&x1" )).isFalse ();
@@ -413,9 +395,7 @@ void nonStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
413
395
lbf .registerBeanDefinition ("x1" , rbd );
414
396
415
397
TestBeanFactory .initialized = false ;
416
- String [] beanNames = lbf .getBeanNamesForType (TestBean .class , true , false );
417
- assertThat (beanNames ).hasSize (1 );
418
- assertThat (beanNames [0 ]).isEqualTo ("x1" );
398
+ assertBeanNamesForType (TestBean .class , true , false , "x1" );
419
399
assertThat (lbf .containsSingleton ("x1" )).isFalse ();
420
400
assertThat (lbf .containsBean ("x1" )).isTrue ();
421
401
assertThat (lbf .containsBean ("&x1" )).isFalse ();
@@ -448,14 +428,10 @@ void nonStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
448
428
assertThat (lbf .isTypeMatch ("&x2" , Object .class )).isFalse ();
449
429
assertThat (lbf .getType ("x2" )).isEqualTo (TestBean .class );
450
430
assertThat (lbf .getType ("&x2" )).isNull ();
451
- assertThat (lbf .getAliases ("x1" ).length ).isEqualTo (1 );
452
- assertThat (lbf .getAliases ("x1" )[0 ]).isEqualTo ("x2" );
453
- assertThat (lbf .getAliases ("&x1" ).length ).isEqualTo (1 );
454
- assertThat (lbf .getAliases ("&x1" )[0 ]).isEqualTo ("&x2" );
455
- assertThat (lbf .getAliases ("x2" ).length ).isEqualTo (1 );
456
- assertThat (lbf .getAliases ("x2" )[0 ]).isEqualTo ("x1" );
457
- assertThat (lbf .getAliases ("&x2" ).length ).isEqualTo (1 );
458
- assertThat (lbf .getAliases ("&x2" )[0 ]).isEqualTo ("&x1" );
431
+ assertThat (lbf .getAliases ("x1" )).containsExactly ("x2" );
432
+ assertThat (lbf .getAliases ("&x1" )).containsExactly ("&x2" );
433
+ assertThat (lbf .getAliases ("x2" )).containsExactly ("x1" );
434
+ assertThat (lbf .getAliases ("&x2" )).containsExactly ("&x1" );
459
435
}
460
436
461
437
@ Test
@@ -619,8 +595,7 @@ void arrayReferenceByName() {
619
595
lbf .registerSingleton ("string" , "A" );
620
596
621
597
TestBean self = (TestBean ) lbf .getBean ("self" );
622
- assertThat (self .getStringArray ()).hasSize (1 );
623
- assertThat (self .getStringArray ()).contains ("A" );
598
+ assertThat (self .getStringArray ()).containsExactly ("A" );
624
599
}
625
600
626
601
@ Test
@@ -633,8 +608,7 @@ void arrayReferenceByType() {
633
608
lbf .registerSingleton ("string" , "A" );
634
609
635
610
TestBean self = (TestBean ) lbf .getBean ("self" );
636
- assertThat (self .getStringArray ()).hasSize (1 );
637
- assertThat (self .getStringArray ()).contains ("A" );
611
+ assertThat (self .getStringArray ()).containsExactly ("A" );
638
612
}
639
613
640
614
@ Test
@@ -666,8 +640,7 @@ void possibleMatches() {
666
640
.withCauseInstanceOf (NotWritablePropertyException .class )
667
641
.satisfies (ex -> {
668
642
NotWritablePropertyException cause = (NotWritablePropertyException ) ex .getCause ();
669
- assertThat (cause .getPossibleMatches ()).hasSize (1 );
670
- assertThat (cause .getPossibleMatches ()[0 ]).isEqualTo ("age" );
643
+ assertThat (cause .getPossibleMatches ()).containsExactly ("age" );
671
644
});
672
645
}
673
646
@@ -685,7 +658,7 @@ void prototype() {
685
658
lbf = new DefaultListableBeanFactory ();
686
659
p = new Properties ();
687
660
p .setProperty ("kerry.(class)" , TestBean .class .getName ());
688
- p .setProperty ("kerry.(scope)" , "prototype" );
661
+ p .setProperty ("kerry.(scope)" , BeanDefinition . SCOPE_PROTOTYPE );
689
662
p .setProperty ("kerry.age" , "35" );
690
663
registerBeanDefinitions (p );
691
664
kerry1 = (TestBean ) lbf .getBean ("kerry" );
@@ -1145,7 +1118,7 @@ void registerExistingSingletonWithAutowire() {
1145
1118
assertThat (lbf .containsBean ("singletonObject" )).isTrue ();
1146
1119
assertThat (lbf .isSingleton ("singletonObject" )).isTrue ();
1147
1120
assertThat (lbf .getType ("singletonObject" )).isEqualTo (TestBean .class );
1148
- assertThat (lbf .getAliases ("singletonObject" ). length ). isEqualTo ( 0 );
1121
+ assertThat (lbf .getAliases ("singletonObject" )). isEmpty ( );
1149
1122
DependenciesBean test = (DependenciesBean ) lbf .getBean ("test" );
1150
1123
assertThat (lbf .getBean ("singletonObject" )).isEqualTo (singletonObject );
1151
1124
assertThat (test .getSpouse ()).isEqualTo (singletonObject );
@@ -1791,12 +1764,12 @@ void getBeanWithArgsNotCreatedForFactoryBeanChecking() {
1791
1764
assertThat (bean .beanName ).isEqualTo ("bd1" );
1792
1765
assertThat (bean .spouseAge ).isEqualTo (42 );
1793
1766
1794
- assertThat (lbf .getBeanNamesForType (ConstructorDependency .class ). length ). isEqualTo (1 );
1795
- assertThat (lbf .getBeanNamesForType (ConstructorDependencyFactoryBean .class ). length ). isEqualTo (1 );
1796
- assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , Object .class )). length ). isEqualTo (1 );
1797
- assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , String .class )). length ). isEqualTo ( 0 );
1798
- assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , Object .class ), true , true ). length ). isEqualTo (1 );
1799
- assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , String .class ), true , true ). length ). isEqualTo ( 0 );
1767
+ assertThat (lbf .getBeanNamesForType (ConstructorDependency .class )). hasSize (1 );
1768
+ assertThat (lbf .getBeanNamesForType (ConstructorDependencyFactoryBean .class )). hasSize (1 );
1769
+ assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , Object .class ))). hasSize (1 );
1770
+ assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , String .class ))). isEmpty ( );
1771
+ assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , Object .class ), true , true )). hasSize (1 );
1772
+ assertThat (lbf .getBeanNamesForType (ResolvableType .forClassWithGenerics (FactoryBean .class , String .class ), true , true )). isEmpty ( );
1800
1773
}
1801
1774
1802
1775
private RootBeanDefinition createConstructorDependencyBeanDefinition (int age ) {
@@ -1861,46 +1834,29 @@ void getTypeForAbstractFactoryBean() {
1861
1834
1862
1835
@ Test
1863
1836
void getBeanNamesForTypeBeforeFactoryBeanCreation () {
1837
+ FactoryBeanThatShouldntBeCalled .instantiated = false ;
1864
1838
lbf .registerBeanDefinition ("factoryBean" , new RootBeanDefinition (FactoryBeanThatShouldntBeCalled .class ));
1865
1839
assertThat (lbf .containsSingleton ("factoryBean" )).isFalse ();
1840
+ assertThat (FactoryBeanThatShouldntBeCalled .instantiated ).isFalse ();
1866
1841
1867
- String [] beanNames = lbf .getBeanNamesForType (Runnable .class , false , false );
1868
- assertThat (beanNames .length ).isEqualTo (1 );
1869
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1870
-
1871
- beanNames = lbf .getBeanNamesForType (Callable .class , false , false );
1872
- assertThat (beanNames .length ).isEqualTo (1 );
1873
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1874
-
1875
- beanNames = lbf .getBeanNamesForType (RepositoryFactoryInformation .class , false , false );
1876
- assertThat (beanNames .length ).isEqualTo (1 );
1877
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1878
-
1879
- beanNames = lbf .getBeanNamesForType (FactoryBean .class , false , false );
1880
- assertThat (beanNames .length ).isEqualTo (1 );
1881
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1842
+ assertBeanNamesForType (Runnable .class , false , false , "&factoryBean" );
1843
+ assertBeanNamesForType (Callable .class , false , false , "&factoryBean" );
1844
+ assertBeanNamesForType (RepositoryFactoryInformation .class , false , false , "&factoryBean" );
1845
+ assertBeanNamesForType (FactoryBean .class , false , false , "&factoryBean" );
1882
1846
}
1883
1847
1884
1848
@ Test
1885
1849
void getBeanNamesForTypeAfterFactoryBeanCreation () {
1850
+ FactoryBeanThatShouldntBeCalled .instantiated = false ;
1886
1851
lbf .registerBeanDefinition ("factoryBean" , new RootBeanDefinition (FactoryBeanThatShouldntBeCalled .class ));
1887
1852
lbf .getBean ("&factoryBean" );
1853
+ assertThat (FactoryBeanThatShouldntBeCalled .instantiated ).isTrue ();
1854
+ assertThat (lbf .containsSingleton ("factoryBean" )).isTrue ();
1888
1855
1889
- String [] beanNames = lbf .getBeanNamesForType (Runnable .class , false , false );
1890
- assertThat (beanNames .length ).isEqualTo (1 );
1891
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1892
-
1893
- beanNames = lbf .getBeanNamesForType (Callable .class , false , false );
1894
- assertThat (beanNames .length ).isEqualTo (1 );
1895
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1896
-
1897
- beanNames = lbf .getBeanNamesForType (RepositoryFactoryInformation .class , false , false );
1898
- assertThat (beanNames .length ).isEqualTo (1 );
1899
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1900
-
1901
- beanNames = lbf .getBeanNamesForType (FactoryBean .class , false , false );
1902
- assertThat (beanNames .length ).isEqualTo (1 );
1903
- assertThat (beanNames [0 ]).isEqualTo ("&factoryBean" );
1856
+ assertBeanNamesForType (Runnable .class , false , false , "&factoryBean" );
1857
+ assertBeanNamesForType (Callable .class , false , false , "&factoryBean" );
1858
+ assertBeanNamesForType (RepositoryFactoryInformation .class , false , false , "&factoryBean" );
1859
+ assertBeanNamesForType (FactoryBean .class , false , false , "&factoryBean" );
1904
1860
}
1905
1861
1906
1862
/**
@@ -2165,26 +2121,23 @@ void circularReferenceThroughAutowiring() {
2165
2121
RootBeanDefinition bd = new RootBeanDefinition (ConstructorDependencyBean .class );
2166
2122
bd .setAutowireMode (RootBeanDefinition .AUTOWIRE_CONSTRUCTOR );
2167
2123
lbf .registerBeanDefinition ("test" , bd );
2168
- assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (
2169
- lbf ::preInstantiateSingletons );
2124
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (lbf ::preInstantiateSingletons );
2170
2125
}
2171
2126
2172
2127
@ Test
2173
2128
void circularReferenceThroughFactoryBeanAutowiring () {
2174
2129
RootBeanDefinition bd = new RootBeanDefinition (ConstructorDependencyFactoryBean .class );
2175
2130
bd .setAutowireMode (RootBeanDefinition .AUTOWIRE_CONSTRUCTOR );
2176
2131
lbf .registerBeanDefinition ("test" , bd );
2177
- assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (
2178
- lbf ::preInstantiateSingletons );
2132
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (lbf ::preInstantiateSingletons );
2179
2133
}
2180
2134
2181
2135
@ Test
2182
2136
void circularReferenceThroughFactoryBeanTypeCheck () {
2183
2137
RootBeanDefinition bd = new RootBeanDefinition (ConstructorDependencyFactoryBean .class );
2184
2138
bd .setAutowireMode (RootBeanDefinition .AUTOWIRE_CONSTRUCTOR );
2185
2139
lbf .registerBeanDefinition ("test" , bd );
2186
- assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (() ->
2187
- lbf .getBeansOfType (String .class ));
2140
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (() -> lbf .getBeansOfType (String .class ));
2188
2141
}
2189
2142
2190
2143
@ Test
@@ -2211,8 +2164,7 @@ void constructorDependencyWithUnresolvableClass() {
2211
2164
RootBeanDefinition bd = new RootBeanDefinition (ConstructorDependencyWithClassResolution .class );
2212
2165
bd .getConstructorArgumentValues ().addGenericArgumentValue ("java.lang.Strin" );
2213
2166
lbf .registerBeanDefinition ("test" , bd );
2214
- assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (
2215
- lbf ::preInstantiateSingletons );
2167
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (lbf ::preInstantiateSingletons );
2216
2168
}
2217
2169
2218
2170
@ Test
@@ -2236,7 +2188,13 @@ void beanDefinitionWithAbstractClass() {
2236
2188
@ Test
2237
2189
void prototypeFactoryBeanNotEagerlyCalled () {
2238
2190
lbf .registerBeanDefinition ("test" , new RootBeanDefinition (FactoryBeanThatShouldntBeCalled .class ));
2239
- lbf .preInstantiateSingletons ();
2191
+ assertThatNoException ().isThrownBy (lbf ::preInstantiateSingletons );
2192
+ }
2193
+
2194
+ @ Test
2195
+ void prototypeFactoryBeanNotEagerlyCalledInCaseOfBeanClassName () {
2196
+ lbf .registerBeanDefinition ("test" , new RootBeanDefinition (FactoryBeanThatShouldntBeCalled .class .getName (), null , null ));
2197
+ assertThatNoException ().isThrownBy (lbf ::preInstantiateSingletons );
2240
2198
}
2241
2199
2242
2200
@ Test
@@ -2276,13 +2234,6 @@ void smartInitFactory() {
2276
2234
assertThat (factory .initialized ).isTrue ();
2277
2235
}
2278
2236
2279
- @ Test
2280
- void prototypeFactoryBeanNotEagerlyCalledInCaseOfBeanClassName () {
2281
- lbf .registerBeanDefinition ("test" ,
2282
- new RootBeanDefinition (FactoryBeanThatShouldntBeCalled .class .getName (), null , null ));
2283
- lbf .preInstantiateSingletons ();
2284
- }
2285
-
2286
2237
@ Test
2287
2238
void prototypeStringCreatedRepeatedly () {
2288
2239
RootBeanDefinition stringDef = new RootBeanDefinition (String .class );
@@ -2462,10 +2413,7 @@ private void findTypeOfPrototypeFactoryMethodOnBeanInstance(boolean singleton) {
2462
2413
lbf .registerBeanDefinition ("fmWithArgs" , factoryMethodDefinitionWithArgs );
2463
2414
2464
2415
assertThat (lbf .getBeanDefinitionCount ()).isEqualTo (4 );
2465
- List <String > tbNames = Arrays .asList (lbf .getBeanNamesForType (TestBean .class ));
2466
- assertThat (tbNames .contains ("fmWithProperties" )).isTrue ();
2467
- assertThat (tbNames .contains ("fmWithArgs" )).isTrue ();
2468
- assertThat (tbNames .size ()).isEqualTo (2 );
2416
+ assertBeanNamesForType (TestBean .class , true , true , "fmWithProperties" , "fmWithArgs" );
2469
2417
2470
2418
TestBean tb = (TestBean ) lbf .getBean ("fmWithProperties" );
2471
2419
TestBean second = (TestBean ) lbf .getBean ("fmWithProperties" );
@@ -2669,6 +2617,19 @@ private int registerBeanDefinitions(Properties p, String prefix) {
2669
2617
return (new org .springframework .beans .factory .support .PropertiesBeanDefinitionReader (lbf )).registerBeanDefinitions (p , prefix );
2670
2618
}
2671
2619
2620
+ private void assertBeanNamesForType (Class <?> type , boolean includeNonSingletons , boolean allowEagerInit , String ... names ) {
2621
+ if (names .length == 0 ) {
2622
+ assertThat (lbf .getBeanNamesForType (type , includeNonSingletons , allowEagerInit ))
2623
+ .as ("bean names for type " + type .getName ())
2624
+ .isEmpty ();
2625
+ }
2626
+ else {
2627
+ assertThat (lbf .getBeanNamesForType (type , includeNonSingletons , allowEagerInit ))
2628
+ .as ("bean names for type " + type .getName ())
2629
+ .containsExactly (names );
2630
+ }
2631
+ }
2632
+
2672
2633
2673
2634
public static class NoDependencies {
2674
2635
@@ -2859,6 +2820,12 @@ public static abstract class RepositoryFactoryBeanSupport<T extends Repository<S
2859
2820
public static class FactoryBeanThatShouldntBeCalled <T extends Repository <S , ID >, S , ID extends Serializable >
2860
2821
extends RepositoryFactoryBeanSupport <T , S , ID > implements Runnable , Callable <T > {
2861
2822
2823
+ static boolean instantiated = false ;
2824
+
2825
+ {
2826
+ instantiated = true ;
2827
+ }
2828
+
2862
2829
@ Override
2863
2830
public T getObject () {
2864
2831
throw new IllegalStateException ();
0 commit comments