@ -630,6 +630,62 @@ public class InjectAnnotationBeanPostProcessorTests {
@@ -630,6 +630,62 @@ public class InjectAnnotationBeanPostProcessorTests {
bf . destroySingletons ( ) ;
}
@Test
public void testOptionalListFieldInjectionWithBeanAvailable ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( OptionalListFieldInjectionBean . class ) ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
OptionalListFieldInjectionBean bean = ( OptionalListFieldInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertTrue ( bean . getTestBean ( ) . isPresent ( ) ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) . get ( ) . get ( 0 ) ) ;
bf . destroySingletons ( ) ;
}
@Test
public void testOptionalListFieldInjectionWithBeanNotAvailable ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( OptionalListFieldInjectionBean . class ) ) ;
OptionalListFieldInjectionBean bean = ( OptionalListFieldInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertFalse ( bean . getTestBean ( ) . isPresent ( ) ) ;
bf . destroySingletons ( ) ;
}
@Test
public void testOptionalListMethodInjectionWithBeanAvailable ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( OptionalListMethodInjectionBean . class ) ) ;
bf . registerBeanDefinition ( "testBean" , new RootBeanDefinition ( TestBean . class ) ) ;
OptionalListMethodInjectionBean bean = ( OptionalListMethodInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertTrue ( bean . getTestBean ( ) . isPresent ( ) ) ;
assertSame ( bf . getBean ( "testBean" ) , bean . getTestBean ( ) . get ( ) . get ( 0 ) ) ;
bf . destroySingletons ( ) ;
}
@Test
public void testOptionalListMethodInjectionWithBeanNotAvailable ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor ( ) ;
bpp . setBeanFactory ( bf ) ;
bf . addBeanPostProcessor ( bpp ) ;
bf . registerBeanDefinition ( "annotatedBean" , new RootBeanDefinition ( OptionalListMethodInjectionBean . class ) ) ;
OptionalListMethodInjectionBean bean = ( OptionalListMethodInjectionBean ) bf . getBean ( "annotatedBean" ) ;
assertFalse ( bean . getTestBean ( ) . isPresent ( ) ) ;
bf . destroySingletons ( ) ;
}
@Test
public void testProviderOfOptionalFieldInjectionWithBeanAvailable ( ) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ( ) ;
@ -1239,6 +1295,32 @@ public class InjectAnnotationBeanPostProcessorTests {
@@ -1239,6 +1295,32 @@ public class InjectAnnotationBeanPostProcessorTests {
}
public static class OptionalListFieldInjectionBean {
@Inject
private Optional < List < TestBean > > testBean ;
public Optional < List < TestBean > > getTestBean ( ) {
return this . testBean ;
}
}
public static class OptionalListMethodInjectionBean {
private Optional < List < TestBean > > testBean ;
@Inject
public void setTestBean ( Optional < List < TestBean > > testBeanFactory ) {
this . testBean = testBeanFactory ;
}
public Optional < List < TestBean > > getTestBean ( ) {
return this . testBean ;
}
}
public static class ProviderOfOptionalFieldInjectionBean {
@Inject