@ -1434,7 +1434,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1434,7 +1434,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testGetBeanByTypeWithPrimary ( ) throws Exception {
public void testGetBeanByTypeWithPrimary ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( TestBean . class ) ;
bd1 . setLazyInit ( true ) ;
@ -1448,7 +1448,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1448,7 +1448,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testGetBeanByTypeWithMultiplePrimary ( ) throws Exception {
public void testGetBeanByTypeWithMultiplePrimary ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( TestBean . class ) ;
bd1 . setPrimary ( true ) ;
@ -1462,19 +1462,39 @@ public class DefaultListableBeanFactoryTests {
@@ -1462,19 +1462,39 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testGetBeanByTypeWithPriority ( ) throws Exception {
public void testGetBeanByTypeWithPriority ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
lbf . setDependencyComparator ( AnnotationAwareOrderComparator . INSTANCE ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( HighPriorityTestBean . class ) ;
RootBeanDefinition bd2 = new RootBeanDefinition ( LowPriorityTestBean . class ) ;
RootBeanDefinition bd3 = new RootBeanDefinition ( NullTestBeanFactoryBean . class ) ;
lbf . registerBeanDefinition ( "bd1" , bd1 ) ;
lbf . registerBeanDefinition ( "bd2" , bd2 ) ;
lbf . registerBeanDefinition ( "bd3" , bd3 ) ;
lbf . preInstantiateSingletons ( ) ;
TestBean bean = lbf . getBean ( TestBean . class ) ;
assertThat ( bean . getBeanName ( ) , equalTo ( "bd1" ) ) ;
}
@Test
public void testGetBeanByTypeWithMultiplePriority ( ) throws Exception {
public void testMapInjectionWithPriority ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
lbf . setDependencyComparator ( AnnotationAwareOrderComparator . INSTANCE ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( HighPriorityTestBean . class ) ;
RootBeanDefinition bd2 = new RootBeanDefinition ( LowPriorityTestBean . class ) ;
RootBeanDefinition bd3 = new RootBeanDefinition ( NullTestBeanFactoryBean . class ) ;
RootBeanDefinition bd4 = new RootBeanDefinition ( TestBeanRecipient . class , RootBeanDefinition . AUTOWIRE_CONSTRUCTOR , false ) ;
lbf . registerBeanDefinition ( "bd1" , bd1 ) ;
lbf . registerBeanDefinition ( "bd2" , bd2 ) ;
lbf . registerBeanDefinition ( "bd3" , bd3 ) ;
lbf . registerBeanDefinition ( "bd4" , bd4 ) ;
lbf . preInstantiateSingletons ( ) ;
TestBean bean = lbf . getBean ( TestBeanRecipient . class ) . testBean ;
assertThat ( bean . getBeanName ( ) , equalTo ( "bd1" ) ) ;
}
@Test
public void testGetBeanByTypeWithMultiplePriority ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
lbf . setDependencyComparator ( AnnotationAwareOrderComparator . INSTANCE ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( HighPriorityTestBean . class ) ;
@ -1483,12 +1503,12 @@ public class DefaultListableBeanFactoryTests {
@@ -1483,12 +1503,12 @@ public class DefaultListableBeanFactoryTests {
lbf . registerBeanDefinition ( "bd2" , bd2 ) ;
thrown . expect ( NoUniqueBeanDefinitionException . class ) ;
thrown . expectMessage ( containsString ( "Multiple beans found with the same priority" ) ) ;
thrown . expectMessage ( containsString ( "5" ) ) ; // conflicting priority
thrown . expectMessage ( containsString ( "5" ) ) ; // conflicting priority
lbf . getBean ( TestBean . class ) ;
}
@Test
public void testGetBeanByTypeWithPriorityAndNullInstance ( ) throws Exception {
public void testGetBeanByTypeWithPriorityAndNullInstance ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
lbf . setDependencyComparator ( AnnotationAwareOrderComparator . INSTANCE ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( HighPriorityTestBean . class ) ;
@ -1500,7 +1520,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1500,7 +1520,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testGetBeanByTypePrimaryHasPrecedenceOverPriority ( ) throws Exception {
public void testGetBeanByTypePrimaryHasPrecedenceOverPriority ( ) {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ( ) ;
lbf . setDependencyComparator ( AnnotationAwareOrderComparator . INSTANCE ) ;
RootBeanDefinition bd1 = new RootBeanDefinition ( HighPriorityTestBean . class ) ;
@ -1522,7 +1542,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1522,7 +1542,7 @@ public class DefaultListableBeanFactoryTests {
lbf . registerBeanDefinition ( "bd1" , bd1 ) ;
lbf . registerBeanDefinition ( "na1" , na1 ) ;
TestBean actual = lbf . getBean ( TestBean . class ) ; // na1 was filtered
TestBean actual = lbf . getBean ( TestBean . class ) ; // na1 was filtered
assertSame ( lbf . getBean ( "bd1" , TestBean . class ) , actual ) ;
lbf . registerBeanDefinition ( "bd2" , bd2 ) ;
@ -1605,7 +1625,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1605,7 +1625,7 @@ public class DefaultListableBeanFactoryTests {
lbf . registerBeanDefinition ( "bd1" , bd1 ) ;
lbf . registerBeanDefinition ( "na1" , na1 ) ;
ConstructorDependency actual = lbf . getBean ( ConstructorDependency . class , 42 ) ; // na1 was filtered
ConstructorDependency actual = lbf . getBean ( ConstructorDependency . class , 42 ) ; // na1 was filtered
assertThat ( actual . beanName , equalTo ( "bd1" ) ) ;
lbf . registerBeanDefinition ( "bd2" , bd2 ) ;
@ -1850,7 +1870,7 @@ public class DefaultListableBeanFactoryTests {
@@ -1850,7 +1870,7 @@ public class DefaultListableBeanFactoryTests {
// expected
assertNotNull ( "Exception should have cause" , ex . getCause ( ) ) ;
assertEquals ( "Wrong cause type" , NoUniqueBeanDefinitionException . class , ex . getCause ( ) . getClass ( ) ) ;
assertTrue ( ex . getMessage ( ) . contains ( "5" ) ) ; // conflicting priority
assertTrue ( ex . getMessage ( ) . contains ( "5" ) ) ; // conflicting priority
}
}
@ -2278,7 +2298,7 @@ public class DefaultListableBeanFactoryTests {
@@ -2278,7 +2298,7 @@ public class DefaultListableBeanFactoryTests {
/ * *
* @Test
* public void testPrototypeCreationIsFastEnough2 ( ) throws Exception {
* public void testPrototypeCreationIsFastEnough2 ( ) {
* if ( factoryLog . isTraceEnabled ( ) | | factoryLog . isDebugEnabled ( ) ) {
* // Skip this test: Trace logging blows the time limit.
* return ;
@ -2576,7 +2596,7 @@ public class DefaultListableBeanFactoryTests {
@@ -2576,7 +2596,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test ( expected = IllegalStateException . class )
public void testScopingBeanToUnregisteredScopeResultsInAnException ( ) throws Exception {
public void testScopingBeanToUnregisteredScopeResultsInAnException ( ) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder . rootBeanDefinition ( TestBean . class ) ;
AbstractBeanDefinition beanDefinition = builder . getBeanDefinition ( ) ;
beanDefinition . setScope ( "he put himself so low could hardly look me in the face" ) ;
@ -2587,7 +2607,7 @@ public class DefaultListableBeanFactoryTests {
@@ -2587,7 +2607,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testExplicitScopeInheritanceForChildBeanDefinitions ( ) throws Exception {
public void testExplicitScopeInheritanceForChildBeanDefinitions ( ) {
String theChildScope = "bonanza!" ;
RootBeanDefinition parent = new RootBeanDefinition ( ) ;
@ -2606,7 +2626,7 @@ public class DefaultListableBeanFactoryTests {
@@ -2606,7 +2626,7 @@ public class DefaultListableBeanFactoryTests {
}
@Test
public void testScopeInheritanceForChildBeanDefinitions ( ) throws Exception {
public void testScopeInheritanceForChildBeanDefinitions ( ) {
RootBeanDefinition parent = new RootBeanDefinition ( ) ;
parent . setScope ( "bonanza!" ) ;
@ -2993,7 +3013,7 @@ public class DefaultListableBeanFactoryTests {
@@ -2993,7 +3013,7 @@ public class DefaultListableBeanFactoryTests {
}
@Override
public T call ( ) throws Exception {
public T call ( ) {
throw new IllegalStateException ( ) ;
}
}
@ -3004,7 +3024,7 @@ public class DefaultListableBeanFactoryTests {
@@ -3004,7 +3024,7 @@ public class DefaultListableBeanFactoryTests {
public boolean initialized = false ;
@Override
public Object getObject ( ) throws Exception {
public Object getObject ( ) {
this . initialized = true ;
return "" ;
}
@ -3026,7 +3046,7 @@ public class DefaultListableBeanFactoryTests {
@@ -3026,7 +3046,7 @@ public class DefaultListableBeanFactoryTests {
public boolean initialized = false ;
@Override
public Object getObject ( ) throws Exception {
public Object getObject ( ) {
this . initialized = true ;
return "" ;
}
@ -3258,7 +3278,7 @@ public class DefaultListableBeanFactoryTests {
@@ -3258,7 +3278,7 @@ public class DefaultListableBeanFactoryTests {
private static class NullTestBeanFactoryBean < T > implements FactoryBean < TestBean > {
@Override
public TestBean getObject ( ) throws Exception {
public TestBean getObject ( ) {
return null ;
}
@ -3274,6 +3294,16 @@ public class DefaultListableBeanFactoryTests {
@@ -3274,6 +3294,16 @@ public class DefaultListableBeanFactoryTests {
}
private static class TestBeanRecipient {
public TestBean testBean ;
public TestBeanRecipient ( TestBean testBean ) {
this . testBean = testBean ;
}
}
enum NonPublicEnum {
VALUE_1 , VALUE_2 ;