|
|
|
|
@ -991,7 +991,7 @@ class ConfigurationClassPostProcessorTests {
@@ -991,7 +991,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testSelfReferenceExclusionForFactoryMethodOnSameBean() { |
|
|
|
|
void selfReferenceExclusionForFactoryMethodOnSameBean() { |
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
bpp.setBeanFactory(beanFactory); |
|
|
|
|
beanFactory.addBeanPostProcessor(bpp); |
|
|
|
|
@ -1005,7 +1005,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1005,7 +1005,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testConfigWithDefaultMethods() { |
|
|
|
|
void configWithDefaultMethods() { |
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
bpp.setBeanFactory(beanFactory); |
|
|
|
|
beanFactory.addBeanPostProcessor(bpp); |
|
|
|
|
@ -1019,7 +1019,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1019,7 +1019,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testConfigWithDefaultMethodsUsingAsm() { |
|
|
|
|
void configWithDefaultMethodsUsingAsm() { |
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
bpp.setBeanFactory(beanFactory); |
|
|
|
|
beanFactory.addBeanPostProcessor(bpp); |
|
|
|
|
@ -1033,7 +1033,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1033,7 +1033,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testConfigWithFailingInit() { // gh-23343
|
|
|
|
|
void configWithFailingInit() { // gh-23343
|
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
bpp.setBeanFactory(beanFactory); |
|
|
|
|
beanFactory.addBeanPostProcessor(bpp); |
|
|
|
|
@ -1047,7 +1047,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1047,7 +1047,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testCircularDependency() { |
|
|
|
|
void circularDependency() { |
|
|
|
|
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
|
|
|
|
bpp.setBeanFactory(beanFactory); |
|
|
|
|
beanFactory.addBeanPostProcessor(bpp); |
|
|
|
|
@ -1061,42 +1061,42 @@ class ConfigurationClassPostProcessorTests {
@@ -1061,42 +1061,42 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testCircularDependencyWithApplicationContext() { |
|
|
|
|
void circularDependencyWithApplicationContext() { |
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class) |
|
|
|
|
.isThrownBy(() -> new AnnotationConfigApplicationContext(A.class, AStrich.class)) |
|
|
|
|
.withMessageContaining("Circular reference"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testPrototypeArgumentThroughBeanMethodCall() { |
|
|
|
|
void prototypeArgumentThroughBeanMethodCall() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class); |
|
|
|
|
ctx.getBean(FooFactory.class).createFoo(new BarArgument()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testSingletonArgumentThroughBeanMethodCall() { |
|
|
|
|
void singletonArgumentThroughBeanMethodCall() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class); |
|
|
|
|
ctx.getBean(FooFactory.class).createFoo(new BarArgument()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testNullArgumentThroughBeanMethodCall() { |
|
|
|
|
void nullArgumentThroughBeanMethodCall() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class); |
|
|
|
|
ctx.getBean("aFoo"); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testInjectionPointMatchForNarrowTargetReturnType() { |
|
|
|
|
void injectionPointMatchForNarrowTargetReturnType() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class); |
|
|
|
|
assertThat(ctx.getBean(FooImpl.class).bar).isSameAs(ctx.getBean(BarImpl.class)); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testVarargOnBeanMethod() { |
|
|
|
|
void varargOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class); |
|
|
|
|
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).isNotNull(); |
|
|
|
|
@ -1106,7 +1106,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1106,7 +1106,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testEmptyVarargOnBeanMethod() { |
|
|
|
|
void emptyVarargOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class); |
|
|
|
|
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).isNotNull(); |
|
|
|
|
@ -1115,7 +1115,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1115,7 +1115,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testCollectionArgumentOnBeanMethod() { |
|
|
|
|
void collectionArgumentOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class); |
|
|
|
|
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class)); |
|
|
|
|
@ -1123,7 +1123,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1123,7 +1123,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testEmptyCollectionArgumentOnBeanMethod() { |
|
|
|
|
void emptyCollectionArgumentOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class); |
|
|
|
|
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).isEmpty(); |
|
|
|
|
@ -1131,7 +1131,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1131,7 +1131,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testMapArgumentOnBeanMethod() { |
|
|
|
|
void mapArgumentOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class); |
|
|
|
|
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).hasSize(1).containsValue(ctx.getBean(Runnable.class)); |
|
|
|
|
@ -1139,7 +1139,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1139,7 +1139,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testEmptyMapArgumentOnBeanMethod() { |
|
|
|
|
void emptyMapArgumentOnBeanMethod() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class); |
|
|
|
|
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).isEmpty(); |
|
|
|
|
@ -1147,7 +1147,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1147,7 +1147,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testCollectionInjectionFromSameConfigurationClass() { |
|
|
|
|
void collectionInjectionFromSameConfigurationClass() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class); |
|
|
|
|
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class)); |
|
|
|
|
@ -1155,7 +1155,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1155,7 +1155,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testMapInjectionFromSameConfigurationClass() { |
|
|
|
|
void mapInjectionFromSameConfigurationClass() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class); |
|
|
|
|
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class); |
|
|
|
|
assertThat(bean.testBeans).containsOnly(Map.entry("testBean", ctx.getBean(Runnable.class))); |
|
|
|
|
@ -1163,14 +1163,14 @@ class ConfigurationClassPostProcessorTests {
@@ -1163,14 +1163,14 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testBeanLookupFromSameConfigurationClass() { |
|
|
|
|
void beanLookupFromSameConfigurationClass() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class); |
|
|
|
|
assertThat(ctx.getBean(BeanLookupConfiguration.class).getTestBean()).isSameAs(ctx.getBean(TestBean.class)); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testNameClashBetweenConfigurationClassAndBean() { |
|
|
|
|
void nameClashBetweenConfigurationClassAndBean() { |
|
|
|
|
assertThatIllegalStateException() |
|
|
|
|
.isThrownBy(() -> new AnnotationConfigApplicationContext(MyTestBean.class)) |
|
|
|
|
.withMessage("Failed to load bean definitions for configuration class '%s'", MyTestBean.class.getName()) |
|
|
|
|
@ -1179,7 +1179,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1179,7 +1179,7 @@ class ConfigurationClassPostProcessorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testBeanDefinitionRegistryPostProcessorConfig() { |
|
|
|
|
void beanDefinitionRegistryPostProcessorConfig() { |
|
|
|
|
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class); |
|
|
|
|
assertThat(ctx.getBean("myTestBean")).isInstanceOf(TestBean.class); |
|
|
|
|
ctx.close(); |
|
|
|
|
|