1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -1340,10 +1340,10 @@ public void testAutowireBeanByNameWithNoDependencyCheck() {
1340
1340
public void testDependsOnCycle () {
1341
1341
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1342
1342
RootBeanDefinition bd1 = new RootBeanDefinition (TestBean .class );
1343
- bd1 .setDependsOn (new String [] { "tb2" } );
1343
+ bd1 .setDependsOn ("tb2" );
1344
1344
lbf .registerBeanDefinition ("tb1" , bd1 );
1345
1345
RootBeanDefinition bd2 = new RootBeanDefinition (TestBean .class );
1346
- bd2 .setDependsOn (new String [] { "tb1" } );
1346
+ bd2 .setDependsOn ("tb1" );
1347
1347
lbf .registerBeanDefinition ("tb2" , bd2 );
1348
1348
try {
1349
1349
lbf .preInstantiateSingletons ();
@@ -1361,13 +1361,13 @@ public void testDependsOnCycle() {
1361
1361
public void testImplicitDependsOnCycle () {
1362
1362
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1363
1363
RootBeanDefinition bd1 = new RootBeanDefinition (TestBean .class );
1364
- bd1 .setDependsOn (new String [] { "tb2" } );
1364
+ bd1 .setDependsOn ("tb2" );
1365
1365
lbf .registerBeanDefinition ("tb1" , bd1 );
1366
1366
RootBeanDefinition bd2 = new RootBeanDefinition (TestBean .class );
1367
- bd2 .setDependsOn (new String [] { "tb3" } );
1367
+ bd2 .setDependsOn ("tb3" );
1368
1368
lbf .registerBeanDefinition ("tb2" , bd2 );
1369
1369
RootBeanDefinition bd3 = new RootBeanDefinition (TestBean .class );
1370
- bd3 .setDependsOn (new String [] { "tb1" } );
1370
+ bd3 .setDependsOn ("tb1" );
1371
1371
lbf .registerBeanDefinition ("tb3" , bd3 );
1372
1372
try {
1373
1373
lbf .preInstantiateSingletons ();
@@ -1540,7 +1540,7 @@ public void testGetBeanByTypeInstanceWithAmbiguity() {
1540
1540
}
1541
1541
1542
1542
@ Test
1543
- public void testGetBeanByTypeInstanceWithPrimary () throws Exception {
1543
+ public void testGetBeanByTypeInstanceWithPrimary () {
1544
1544
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1545
1545
RootBeanDefinition bd1 = createConstructorDependencyBeanDefinition (99 );
1546
1546
RootBeanDefinition bd2 = createConstructorDependencyBeanDefinition (43 );
@@ -1553,7 +1553,7 @@ public void testGetBeanByTypeInstanceWithPrimary() throws Exception {
1553
1553
}
1554
1554
1555
1555
@ Test
1556
- public void testGetBeanByTypeInstanceWithMultiplePrimary () throws Exception {
1556
+ public void testGetBeanByTypeInstanceWithMultiplePrimary () {
1557
1557
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1558
1558
RootBeanDefinition bd1 = createConstructorDependencyBeanDefinition (99 );
1559
1559
RootBeanDefinition bd2 = createConstructorDependencyBeanDefinition (43 );
@@ -1584,16 +1584,35 @@ public void testGetBeanByTypeInstanceFiltersOutNonAutowireCandidates() {
1584
1584
try {
1585
1585
lbf .getBean (TestBean .class , 67 );
1586
1586
fail ("Should have thrown NoSuchBeanDefinitionException" );
1587
- } catch (NoSuchBeanDefinitionException ex ) {
1587
+ }
1588
+ catch (NoSuchBeanDefinitionException ex ) {
1588
1589
// expected
1589
1590
}
1590
1591
}
1591
1592
1592
- private RootBeanDefinition createConstructorDependencyBeanDefinition (int age ) {
1593
+ @ Test
1594
+ public void testGetBeanWithArgsNotCreatedForFactoryBeanChecking () {
1595
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
1593
1596
RootBeanDefinition bd1 = new RootBeanDefinition (ConstructorDependency .class );
1594
1597
bd1 .setScope (RootBeanDefinition .SCOPE_PROTOTYPE );
1595
- bd1 .getConstructorArgumentValues ().addGenericArgumentValue (String .valueOf (age ));
1596
- return bd1 ;
1598
+ lbf .registerBeanDefinition ("bd1" , bd1 );
1599
+ RootBeanDefinition bd2 = new RootBeanDefinition (ConstructorDependencyFactoryBean .class );
1600
+ bd2 .setScope (RootBeanDefinition .SCOPE_PROTOTYPE );
1601
+ lbf .registerBeanDefinition ("bd2" , bd2 );
1602
+
1603
+ ConstructorDependency bean = lbf .getBean (ConstructorDependency .class , 42 );
1604
+ assertThat (bean .beanName , equalTo ("bd1" ));
1605
+ assertThat (bean .spouseAge , equalTo (42 ));
1606
+
1607
+ assertEquals (1 , lbf .getBeanNamesForType (ConstructorDependency .class ).length );
1608
+ assertEquals (1 , lbf .getBeanNamesForType (ConstructorDependencyFactoryBean .class ).length );
1609
+ }
1610
+
1611
+ private RootBeanDefinition createConstructorDependencyBeanDefinition (int age ) {
1612
+ RootBeanDefinition bd = new RootBeanDefinition (ConstructorDependency .class );
1613
+ bd .setScope (RootBeanDefinition .SCOPE_PROTOTYPE );
1614
+ bd .getConstructorArgumentValues ().addGenericArgumentValue (String .valueOf (age ));
1615
+ return bd ;
1597
1616
}
1598
1617
1599
1618
@ Test
@@ -1664,8 +1683,8 @@ public void testAutowireBeanByTypeWithTwoMatches() {
1664
1683
}
1665
1684
catch (UnsatisfiedDependencyException ex ) {
1666
1685
// expected
1667
- assertTrue (ex .getMessage ().indexOf ("test" ) != - 1 );
1668
- assertTrue (ex .getMessage ().indexOf ("spouse" ) != - 1 );
1686
+ assertTrue (ex .getMessage ().contains ("test" ));
1687
+ assertTrue (ex .getMessage ().contains ("spouse" ));
1669
1688
}
1670
1689
}
1671
1690
@@ -1682,8 +1701,8 @@ public void testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery() {
1682
1701
}
1683
1702
catch (UnsatisfiedDependencyException ex ) {
1684
1703
// expected
1685
- assertTrue (ex .getMessage ().indexOf ("test" ) != - 1 );
1686
- assertTrue (ex .getMessage ().indexOf ("spouse" ) != - 1 );
1704
+ assertTrue (ex .getMessage ().contains ("test" ));
1705
+ assertTrue (ex .getMessage ().contains ("spouse" ));
1687
1706
}
1688
1707
}
1689
1708
0 commit comments