@@ -1434,7 +1434,7 @@ public void testGetBeanByTypeWithAmbiguity() {
1434
1434
}
1435
1435
1436
1436
@ Test
1437
- public void testGetBeanByTypeWithPrimary () throws Exception {
1437
+ public void testGetBeanByTypeWithPrimary () {
1438
1438
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1439
1439
RootBeanDefinition bd1 = new RootBeanDefinition (TestBean .class );
1440
1440
bd1 .setLazyInit (true );
@@ -1448,7 +1448,7 @@ public void testGetBeanByTypeWithPrimary() throws Exception {
1448
1448
}
1449
1449
1450
1450
@ Test
1451
- public void testGetBeanByTypeWithMultiplePrimary () throws Exception {
1451
+ public void testGetBeanByTypeWithMultiplePrimary () {
1452
1452
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1453
1453
RootBeanDefinition bd1 = new RootBeanDefinition (TestBean .class );
1454
1454
bd1 .setPrimary (true );
@@ -1462,19 +1462,39 @@ public void testGetBeanByTypeWithMultiplePrimary() throws Exception {
1462
1462
}
1463
1463
1464
1464
@ Test
1465
- public void testGetBeanByTypeWithPriority () throws Exception {
1465
+ public void testGetBeanByTypeWithPriority () {
1466
1466
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1467
1467
lbf .setDependencyComparator (AnnotationAwareOrderComparator .INSTANCE );
1468
1468
RootBeanDefinition bd1 = new RootBeanDefinition (HighPriorityTestBean .class );
1469
1469
RootBeanDefinition bd2 = new RootBeanDefinition (LowPriorityTestBean .class );
1470
+ RootBeanDefinition bd3 = new RootBeanDefinition (NullTestBeanFactoryBean .class );
1470
1471
lbf .registerBeanDefinition ("bd1" , bd1 );
1471
1472
lbf .registerBeanDefinition ("bd2" , bd2 );
1473
+ lbf .registerBeanDefinition ("bd3" , bd3 );
1474
+ lbf .preInstantiateSingletons ();
1472
1475
TestBean bean = lbf .getBean (TestBean .class );
1473
1476
assertThat (bean .getBeanName (), equalTo ("bd1" ));
1474
1477
}
1475
1478
1476
1479
@ Test
1477
- public void testGetBeanByTypeWithMultiplePriority () throws Exception {
1480
+ public void testMapInjectionWithPriority () {
1481
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1482
+ lbf .setDependencyComparator (AnnotationAwareOrderComparator .INSTANCE );
1483
+ RootBeanDefinition bd1 = new RootBeanDefinition (HighPriorityTestBean .class );
1484
+ RootBeanDefinition bd2 = new RootBeanDefinition (LowPriorityTestBean .class );
1485
+ RootBeanDefinition bd3 = new RootBeanDefinition (NullTestBeanFactoryBean .class );
1486
+ RootBeanDefinition bd4 = new RootBeanDefinition (TestBeanRecipient .class , RootBeanDefinition .AUTOWIRE_CONSTRUCTOR , false );
1487
+ lbf .registerBeanDefinition ("bd1" , bd1 );
1488
+ lbf .registerBeanDefinition ("bd2" , bd2 );
1489
+ lbf .registerBeanDefinition ("bd3" , bd3 );
1490
+ lbf .registerBeanDefinition ("bd4" , bd4 );
1491
+ lbf .preInstantiateSingletons ();
1492
+ TestBean bean = lbf .getBean (TestBeanRecipient .class ).testBean ;
1493
+ assertThat (bean .getBeanName (), equalTo ("bd1" ));
1494
+ }
1495
+
1496
+ @ Test
1497
+ public void testGetBeanByTypeWithMultiplePriority () {
1478
1498
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1479
1499
lbf .setDependencyComparator (AnnotationAwareOrderComparator .INSTANCE );
1480
1500
RootBeanDefinition bd1 = new RootBeanDefinition (HighPriorityTestBean .class );
@@ -1483,12 +1503,12 @@ public void testGetBeanByTypeWithMultiplePriority() throws Exception {
1483
1503
lbf .registerBeanDefinition ("bd2" , bd2 );
1484
1504
thrown .expect (NoUniqueBeanDefinitionException .class );
1485
1505
thrown .expectMessage (containsString ("Multiple beans found with the same priority" ));
1486
- thrown .expectMessage (containsString ("5" )); // conflicting priority
1506
+ thrown .expectMessage (containsString ("5" )); // conflicting priority
1487
1507
lbf .getBean (TestBean .class );
1488
1508
}
1489
1509
1490
1510
@ Test
1491
- public void testGetBeanByTypeWithPriorityAndNullInstance () throws Exception {
1511
+ public void testGetBeanByTypeWithPriorityAndNullInstance () {
1492
1512
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1493
1513
lbf .setDependencyComparator (AnnotationAwareOrderComparator .INSTANCE );
1494
1514
RootBeanDefinition bd1 = new RootBeanDefinition (HighPriorityTestBean .class );
@@ -1500,7 +1520,7 @@ public void testGetBeanByTypeWithPriorityAndNullInstance() throws Exception {
1500
1520
}
1501
1521
1502
1522
@ Test
1503
- public void testGetBeanByTypePrimaryHasPrecedenceOverPriority () throws Exception {
1523
+ public void testGetBeanByTypePrimaryHasPrecedenceOverPriority () {
1504
1524
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1505
1525
lbf .setDependencyComparator (AnnotationAwareOrderComparator .INSTANCE );
1506
1526
RootBeanDefinition bd1 = new RootBeanDefinition (HighPriorityTestBean .class );
@@ -1522,7 +1542,7 @@ public void testGetBeanByTypeFiltersOutNonAutowireCandidates() {
1522
1542
1523
1543
lbf .registerBeanDefinition ("bd1" , bd1 );
1524
1544
lbf .registerBeanDefinition ("na1" , na1 );
1525
- TestBean actual = lbf .getBean (TestBean .class ); // na1 was filtered
1545
+ TestBean actual = lbf .getBean (TestBean .class ); // na1 was filtered
1526
1546
assertSame (lbf .getBean ("bd1" , TestBean .class ), actual );
1527
1547
1528
1548
lbf .registerBeanDefinition ("bd2" , bd2 );
@@ -1605,7 +1625,7 @@ public void testGetBeanByTypeInstanceFiltersOutNonAutowireCandidates() {
1605
1625
1606
1626
lbf .registerBeanDefinition ("bd1" , bd1 );
1607
1627
lbf .registerBeanDefinition ("na1" , na1 );
1608
- ConstructorDependency actual = lbf .getBean (ConstructorDependency .class , 42 ); // na1 was filtered
1628
+ ConstructorDependency actual = lbf .getBean (ConstructorDependency .class , 42 ); // na1 was filtered
1609
1629
assertThat (actual .beanName , equalTo ("bd1" ));
1610
1630
1611
1631
lbf .registerBeanDefinition ("bd2" , bd2 );
@@ -1850,7 +1870,7 @@ public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() {
1850
1870
// expected
1851
1871
assertNotNull ("Exception should have cause" , ex .getCause ());
1852
1872
assertEquals ("Wrong cause type" , NoUniqueBeanDefinitionException .class , ex .getCause ().getClass ());
1853
- assertTrue (ex .getMessage ().contains ("5" )); // conflicting priority
1873
+ assertTrue (ex .getMessage ().contains ("5" )); // conflicting priority
1854
1874
}
1855
1875
}
1856
1876
@@ -2278,7 +2298,7 @@ public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
2278
2298
2279
2299
/**
2280
2300
* @Test
2281
- * public void testPrototypeCreationIsFastEnough2() throws Exception {
2301
+ * public void testPrototypeCreationIsFastEnough2() {
2282
2302
* if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
2283
2303
* // Skip this test: Trace logging blows the time limit.
2284
2304
* return;
@@ -2576,7 +2596,7 @@ private void findTypeOfPrototypeFactoryMethodOnBeanInstance(boolean singleton) {
2576
2596
}
2577
2597
2578
2598
@ Test (expected = IllegalStateException .class )
2579
- public void testScopingBeanToUnregisteredScopeResultsInAnException () throws Exception {
2599
+ public void testScopingBeanToUnregisteredScopeResultsInAnException () {
2580
2600
BeanDefinitionBuilder builder = BeanDefinitionBuilder .rootBeanDefinition (TestBean .class );
2581
2601
AbstractBeanDefinition beanDefinition = builder .getBeanDefinition ();
2582
2602
beanDefinition .setScope ("he put himself so low could hardly look me in the face" );
@@ -2587,7 +2607,7 @@ public void testScopingBeanToUnregisteredScopeResultsInAnException() throws Exce
2587
2607
}
2588
2608
2589
2609
@ Test
2590
- public void testExplicitScopeInheritanceForChildBeanDefinitions () throws Exception {
2610
+ public void testExplicitScopeInheritanceForChildBeanDefinitions () {
2591
2611
String theChildScope = "bonanza!" ;
2592
2612
2593
2613
RootBeanDefinition parent = new RootBeanDefinition ();
@@ -2606,7 +2626,7 @@ public void testExplicitScopeInheritanceForChildBeanDefinitions() throws Excepti
2606
2626
}
2607
2627
2608
2628
@ Test
2609
- public void testScopeInheritanceForChildBeanDefinitions () throws Exception {
2629
+ public void testScopeInheritanceForChildBeanDefinitions () {
2610
2630
RootBeanDefinition parent = new RootBeanDefinition ();
2611
2631
parent .setScope ("bonanza!" );
2612
2632
@@ -2993,7 +3013,7 @@ public void run() {
2993
3013
}
2994
3014
2995
3015
@ Override
2996
- public T call () throws Exception {
3016
+ public T call () {
2997
3017
throw new IllegalStateException ();
2998
3018
}
2999
3019
}
@@ -3004,7 +3024,7 @@ public static class LazyInitFactory implements FactoryBean<Object> {
3004
3024
public boolean initialized = false ;
3005
3025
3006
3026
@ Override
3007
- public Object getObject () throws Exception {
3027
+ public Object getObject () {
3008
3028
this .initialized = true ;
3009
3029
return "" ;
3010
3030
}
@@ -3026,7 +3046,7 @@ public static class EagerInitFactory implements SmartFactoryBean<Object> {
3026
3046
public boolean initialized = false ;
3027
3047
3028
3048
@ Override
3029
- public Object getObject () throws Exception {
3049
+ public Object getObject () {
3030
3050
this .initialized = true ;
3031
3051
return "" ;
3032
3052
}
@@ -3258,7 +3278,7 @@ private static class LowPriorityTestBean extends TestBean {
3258
3278
private static class NullTestBeanFactoryBean <T > implements FactoryBean <TestBean > {
3259
3279
3260
3280
@ Override
3261
- public TestBean getObject () throws Exception {
3281
+ public TestBean getObject () {
3262
3282
return null ;
3263
3283
}
3264
3284
@@ -3274,6 +3294,16 @@ public boolean isSingleton() {
3274
3294
}
3275
3295
3276
3296
3297
+ private static class TestBeanRecipient {
3298
+
3299
+ public TestBean testBean ;
3300
+
3301
+ public TestBeanRecipient (TestBean testBean ) {
3302
+ this .testBean = testBean ;
3303
+ }
3304
+ }
3305
+
3306
+
3277
3307
enum NonPublicEnum {
3278
3308
3279
3309
VALUE_1 , VALUE_2 ;
0 commit comments