|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2018 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.
|
|
29 | 29 | import org.springframework.context.annotation6.ComponentForScanning;
|
30 | 30 | import org.springframework.context.annotation6.ConfigForScanning;
|
31 | 31 | import org.springframework.context.annotation6.Jsr330NamedForScanning;
|
| 32 | +import org.springframework.util.ObjectUtils; |
32 | 33 |
|
33 |
| -import static java.lang.String.format; |
| 34 | +import static java.lang.String.*; |
34 | 35 | import static org.hamcrest.Matchers.*;
|
35 | 36 | import static org.junit.Assert.*;
|
36 | 37 | import static org.springframework.util.StringUtils.*;
|
@@ -210,6 +211,22 @@ public void individualNamedBeanWithSupplierAndCustomizer() {
|
210 | 211 | assertSame(context, context.getBean("b", BeanB.class).applicationContext);
|
211 | 212 | }
|
212 | 213 |
|
| 214 | + @Test |
| 215 | + public void individualBeanWithNullReturningSupplier() { |
| 216 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| 217 | + context.registerBean("a", BeanA.class, () -> null); |
| 218 | + context.registerBean("b", BeanB.class, BeanB::new); |
| 219 | + context.registerBean("c", BeanC.class, BeanC::new); |
| 220 | + context.refresh(); |
| 221 | + |
| 222 | + assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanA.class), "a")); |
| 223 | + assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanB.class), "b")); |
| 224 | + assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c")); |
| 225 | + assertTrue(context.getBeansOfType(BeanA.class).isEmpty()); |
| 226 | + assertSame(context.getBean(BeanB.class), context.getBeansOfType(BeanB.class).values().iterator().next()); |
| 227 | + assertSame(context.getBean(BeanC.class), context.getBeansOfType(BeanC.class).values().iterator().next()); |
| 228 | + } |
| 229 | + |
213 | 230 | @Test
|
214 | 231 | public void individualBeanWithSpecifiedConstructorArguments() {
|
215 | 232 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
|
0 commit comments