@@ -960,11 +960,34 @@ void constructorResourceInjectionWithMultipleCandidates() {
960
960
@ Test
961
961
void constructorResourceInjectionWithNoCandidatesAndNoFallback () {
962
962
bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (ConstructorWithoutFallbackBean .class ));
963
+
963
964
assertThatExceptionOfType (UnsatisfiedDependencyException .class )
964
965
.isThrownBy (() -> bf .getBean ("annotatedBean" ))
965
966
.satisfies (methodParameterDeclaredOn (ConstructorWithoutFallbackBean .class ));
966
967
}
967
968
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
+
968
991
@ Test
969
992
void constructorResourceInjectionWithSometimesNullBeanEarly () {
970
993
RootBeanDefinition bd = new RootBeanDefinition (ConstructorWithNullableArgument .class );
@@ -1193,6 +1216,7 @@ void singleConstructorInjectionWithEmptyCollectionAsNull() {
1193
1216
@ Test
1194
1217
void singleConstructorInjectionWithMissingDependency () {
1195
1218
bf .registerBeanDefinition ("annotatedBean" , new RootBeanDefinition (SingleConstructorOptionalCollectionBean .class ));
1219
+
1196
1220
assertThatExceptionOfType (UnsatisfiedDependencyException .class )
1197
1221
.isThrownBy (() -> bf .getBean ("annotatedBean" ));
1198
1222
}
@@ -1203,6 +1227,7 @@ void singleConstructorInjectionWithNullDependency() {
1203
1227
RootBeanDefinition tb = new RootBeanDefinition (NullFactoryMethods .class );
1204
1228
tb .setFactoryMethodName ("createTestBean" );
1205
1229
bf .registerBeanDefinition ("testBean" , tb );
1230
+
1206
1231
assertThatExceptionOfType (UnsatisfiedDependencyException .class )
1207
1232
.isThrownBy (() -> bf .getBean ("annotatedBean" ));
1208
1233
}
@@ -3060,7 +3085,6 @@ public static class ConstructorWithoutFallbackBean {
3060
3085
3061
3086
protected ITestBean testBean3 ;
3062
3087
3063
- @ Autowired (required = false )
3064
3088
public ConstructorWithoutFallbackBean (ITestBean testBean3 ) {
3065
3089
this .testBean3 = testBean3 ;
3066
3090
}
@@ -3075,7 +3099,6 @@ public static class ConstructorWithNullableArgument {
3075
3099
3076
3100
protected ITestBean testBean3 ;
3077
3101
3078
- @ Autowired (required = false )
3079
3102
public ConstructorWithNullableArgument (@ Nullable ITestBean testBean3 ) {
3080
3103
this .testBean3 = testBean3 ;
3081
3104
}
0 commit comments