@@ -960,11 +960,34 @@ void constructorResourceInjectionWithMultipleCandidates() {
960960 @ Test
961961 void constructorResourceInjectionWithNoCandidatesAndNoFallback () {
962962 bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (ConstructorWithoutFallbackBean .class ));
963+
963964 assertThatExceptionOfType (UnsatisfiedDependencyException .class )
964965 .isThrownBy (() -> bf .getBean ("annotatedBean" ))
965966 .satisfies (methodParameterDeclaredOn (ConstructorWithoutFallbackBean .class ));
966967 }
967968
969+ @ Test
970+ void constructorResourceInjectionWithCandidateAndNoFallback () {
971+ bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (ConstructorWithoutFallbackBean .class ));
972+ RootBeanDefinition tb = new RootBeanDefinition (NullFactoryMethods .class );
973+ tb .setFactoryMethodName ("createTestBean" );
974+ bf .registerBeanDefinition ("testBean" , tb );
975+
976+ bf .getBean ("testBean" );
977+ assertThat (bf .getBean ("annotatedBean" , ConstructorWithoutFallbackBean .class ).getTestBean3 ()).isNull ();
978+ }
979+
980+ @ Test
981+ void constructorResourceInjectionWithNameMatchingCandidateAndNoFallback () {
982+ bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (ConstructorWithoutFallbackBean .class ));
983+ RootBeanDefinition tb = new RootBeanDefinition (NullFactoryMethods .class );
984+ tb .setFactoryMethodName ("createTestBean" );
985+ bf .registerBeanDefinition ("testBean3" , tb );
986+
987+ bf .getBean ("testBean3" );
988+ assertThat (bf .getBean ("annotatedBean" , ConstructorWithoutFallbackBean .class ).getTestBean3 ()).isNull ();
989+ }
990+
968991 @ Test
969992 void constructorResourceInjectionWithSometimesNullBeanEarly () {
970993 RootBeanDefinition bd = new RootBeanDefinition (ConstructorWithNullableArgument .class );
@@ -1193,6 +1216,7 @@ void singleConstructorInjectionWithEmptyCollectionAsNull() {
11931216 @ Test
11941217 void singleConstructorInjectionWithMissingDependency () {
11951218 bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (SingleConstructorOptionalCollectionBean .class ));
1219+
11961220 assertThatExceptionOfType (UnsatisfiedDependencyException .class )
11971221 .isThrownBy (() -> bf .getBean ("annotatedBean" ));
11981222 }
@@ -1203,6 +1227,7 @@ void singleConstructorInjectionWithNullDependency() {
12031227 RootBeanDefinition tb = new RootBeanDefinition (NullFactoryMethods .class );
12041228 tb .setFactoryMethodName ("createTestBean" );
12051229 bf .registerBeanDefinition ("testBean" , tb );
1230+
12061231 assertThatExceptionOfType (UnsatisfiedDependencyException .class )
12071232 .isThrownBy (() -> bf .getBean ("annotatedBean" ));
12081233 }
@@ -3060,7 +3085,6 @@ public static class ConstructorWithoutFallbackBean {
30603085
30613086 protected ITestBean testBean3 ;
30623087
3063- @ Autowired (required = false )
30643088 public ConstructorWithoutFallbackBean (ITestBean testBean3 ) {
30653089 this .testBean3 = testBean3 ;
30663090 }
@@ -3075,7 +3099,6 @@ public static class ConstructorWithNullableArgument {
30753099
30763100 protected ITestBean testBean3 ;
30773101
3078- @ Autowired (required = false )
30793102 public ConstructorWithNullableArgument (@ Nullable ITestBean testBean3 ) {
30803103 this .testBean3 = testBean3 ;
30813104 }
0 commit comments