@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2022 the original author or authors .
* Copyright 2002 - 2024 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -321,8 +321,8 @@ class ConfigurationClassPostProcessorTests {
@@ -321,8 +321,8 @@ class ConfigurationClassPostProcessorTests {
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor ( ) ;
pp . setEnvironment ( new StandardEnvironment ( ) ) ;
pp . postProcessBeanFactory ( beanFactory ) ;
assertThatExceptionOfType ( NoSuchBeanDefinitionException . class ) . isThrownBy ( ( ) - >
beanFactory . getBean ( SimpleComponent . class ) ) ;
assertThatExceptionOfType ( NoSuchBeanDefinitionException . class )
. isThrownBy ( ( ) - > beanFactory . getBean ( SimpleComponent . class ) ) ;
}
@Test
@ -372,11 +372,11 @@ class ConfigurationClassPostProcessorTests {
@@ -372,11 +372,11 @@ class ConfigurationClassPostProcessorTests {
beanFactory . registerBeanDefinition ( "config" , new RootBeanDefinition ( SingletonBeanConfig . class ) ) ;
beanFactory . setAllowBeanDefinitionOverriding ( false ) ;
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor ( ) ;
assertThatExceptionOfType ( BeanDefinitionStoreException . class ) . isThrownBy ( ( ) - >
pp . postProcessBeanFactory ( beanFactory ) )
. withMessageContaining ( "bar" )
. withMessageContaining ( "SingletonBeanConfig" )
. withMessageContaining ( TestBean . class . getName ( ) ) ;
assertThatExceptionOfType ( BeanDefinitionStoreException . class )
. isThrownBy ( ( ) - > pp . postProcessBeanFactory ( beanFactory ) )
. withMessageContaining ( "bar" )
. withMessageContaining ( "SingletonBeanConfig" )
. withMessageContaining ( TestBean . class . getName ( ) ) ;
}
@Test // gh-25430
@ -429,12 +429,12 @@ class ConfigurationClassPostProcessorTests {
@@ -429,12 +429,12 @@ class ConfigurationClassPostProcessorTests {
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor ( ) ;
pp . postProcessBeanFactory ( beanFactory ) ;
assertThatExceptionOfType ( BeanCreationException . class ) . isThrownBy ( ( ) - >
beanFactory . getBean ( Bar . class ) )
. withMessageContaining ( "OverridingSingletonBeanConfig.foo" )
. withMessageContaining ( ExtendedFoo . class . getName ( ) )
. withMessageContaining ( Foo . class . getName ( ) )
. withMessageContaining ( "InvalidOverridingSingletonBeanConfig" ) ;
assertThatExceptionOfType ( BeanCreationException . class )
. isThrownBy ( ( ) - > beanFactory . getBean ( Bar . class ) )
. withMessageContaining ( "OverridingSingletonBeanConfig.foo" )
. withMessageContaining ( ExtendedFoo . class . getName ( ) )
. withMessageContaining ( Foo . class . getName ( ) )
. withMessageContaining ( "InvalidOverridingSingletonBeanConfig" ) ;
}
@Test // SPR-15384
@ -985,16 +985,16 @@ class ConfigurationClassPostProcessorTests {
@@ -985,16 +985,16 @@ class ConfigurationClassPostProcessorTests {
beanFactory . registerBeanDefinition ( "configClass1" , new RootBeanDefinition ( A . class ) ) ;
beanFactory . registerBeanDefinition ( "configClass2" , new RootBeanDefinition ( AStrich . class ) ) ;
new ConfigurationClassPostProcessor ( ) . postProcessBeanFactory ( beanFactory ) ;
assertThatExceptionOfType ( BeanCreationException . class ) . isThrownBy (
beanFactory : : preInstantiateSingletons )
. withMessageContaining ( "Circular reference" ) ;
assertThatExceptionOfType ( BeanCreationException . class )
. isThrownBy ( beanFactory : : preInstantiateSingletons )
. withMessageContaining ( "Circular reference" ) ;
}
@Test
void testCircularDependencyWithApplicationContext ( ) {
assertThatExceptionOfType ( BeanCreationException . class ) . isThrownBy ( ( ) - >
new AnnotationConfigApplicationContext ( A . class , AStrich . class ) )
. withMessageContaining ( "Circular reference" ) ;
assertThatExceptionOfType ( BeanCreationException . class )
. isThrownBy ( ( ) - > new AnnotationConfigApplicationContext ( A . class , AStrich . class ) )
. withMessageContaining ( "Circular reference" ) ;
}
@Test
@ -1048,9 +1048,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1048,9 +1048,7 @@ class ConfigurationClassPostProcessorTests {
void testCollectionArgumentOnBeanMethod ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( CollectionArgumentConfiguration . class , TestBean . class ) ;
CollectionArgumentConfiguration bean = ctx . getBean ( CollectionArgumentConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans ) . hasSize ( 1 ) ;
assertThat ( bean . testBeans . get ( 0 ) ) . isSameAs ( ctx . getBean ( TestBean . class ) ) ;
assertThat ( bean . testBeans ) . containsExactly ( ctx . getBean ( TestBean . class ) ) ;
ctx . close ( ) ;
}
@ -1058,8 +1056,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1058,8 +1056,7 @@ class ConfigurationClassPostProcessorTests {
void testEmptyCollectionArgumentOnBeanMethod ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( CollectionArgumentConfiguration . class ) ;
CollectionArgumentConfiguration bean = ctx . getBean ( CollectionArgumentConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans . isEmpty ( ) ) . isTrue ( ) ;
assertThat ( bean . testBeans ) . isEmpty ( ) ;
ctx . close ( ) ;
}
@ -1067,9 +1064,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1067,9 +1064,7 @@ class ConfigurationClassPostProcessorTests {
void testMapArgumentOnBeanMethod ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( MapArgumentConfiguration . class , DummyRunnable . class ) ;
MapArgumentConfiguration bean = ctx . getBean ( MapArgumentConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans ) . hasSize ( 1 ) ;
assertThat ( bean . testBeans . values ( ) . iterator ( ) . next ( ) ) . isSameAs ( ctx . getBean ( Runnable . class ) ) ;
assertThat ( bean . testBeans ) . hasSize ( 1 ) . containsValue ( ctx . getBean ( Runnable . class ) ) ;
ctx . close ( ) ;
}
@ -1077,8 +1072,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1077,8 +1072,7 @@ class ConfigurationClassPostProcessorTests {
void testEmptyMapArgumentOnBeanMethod ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( MapArgumentConfiguration . class ) ;
MapArgumentConfiguration bean = ctx . getBean ( MapArgumentConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans . isEmpty ( ) ) . isTrue ( ) ;
assertThat ( bean . testBeans ) . isEmpty ( ) ;
ctx . close ( ) ;
}
@ -1086,9 +1080,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1086,9 +1080,7 @@ class ConfigurationClassPostProcessorTests {
void testCollectionInjectionFromSameConfigurationClass ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( CollectionInjectionConfiguration . class ) ;
CollectionInjectionConfiguration bean = ctx . getBean ( CollectionInjectionConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans ) . hasSize ( 1 ) ;
assertThat ( bean . testBeans . get ( 0 ) ) . isSameAs ( ctx . getBean ( TestBean . class ) ) ;
assertThat ( bean . testBeans ) . containsExactly ( ctx . getBean ( TestBean . class ) ) ;
ctx . close ( ) ;
}
@ -1096,25 +1088,21 @@ class ConfigurationClassPostProcessorTests {
@@ -1096,25 +1088,21 @@ class ConfigurationClassPostProcessorTests {
void testMapInjectionFromSameConfigurationClass ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( MapInjectionConfiguration . class ) ;
MapInjectionConfiguration bean = ctx . getBean ( MapInjectionConfiguration . class ) ;
assertThat ( bean . testBeans ) . isNotNull ( ) ;
assertThat ( bean . testBeans ) . hasSize ( 1 ) ;
assertThat ( bean . testBeans . get ( "testBean" ) ) . isSameAs ( ctx . getBean ( Runnable . class ) ) ;
assertThat ( bean . testBeans ) . containsOnly ( Map . entry ( "testBean" , ctx . getBean ( Runnable . class ) ) ) ;
ctx . close ( ) ;
}
@Test
void testBeanLookupFromSameConfigurationClass ( ) {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext ( BeanLookupConfiguration . class ) ;
BeanLookupConfiguration bean = ctx . getBean ( BeanLookupConfiguration . class ) ;
assertThat ( bean . getTestBean ( ) ) . isNotNull ( ) ;
assertThat ( bean . getTestBean ( ) ) . isSameAs ( ctx . getBean ( TestBean . class ) ) ;
assertThat ( ctx . getBean ( BeanLookupConfiguration . class ) . getTestBean ( ) ) . isSameAs ( ctx . getBean ( TestBean . class ) ) ;
ctx . close ( ) ;
}
@Test
void testNameClashBetweenConfigurationClassAndBean ( ) {
assertThatExceptionOfType ( BeanDefinitionStoreException . class )
. isThrownBy ( ( ) - > new AnnotationConfigApplicationContext ( MyTestBean . class ) . getBean ( "myTestBean" , TestBean . class ) ) ;
. isThrownBy ( ( ) - > new AnnotationConfigApplicationContext ( MyTestBean . class ) . getBean ( "myTestBean" , TestBean . class ) ) ;
}
@Test
@ -1131,11 +1119,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1131,11 +1119,11 @@ class ConfigurationClassPostProcessorTests {
@Order ( 1 )
static class SingletonBeanConfig {
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1143,11 +1131,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1143,11 +1131,11 @@ class ConfigurationClassPostProcessorTests {
@Configuration ( proxyBeanMethods = false )
static class NonEnhancedSingletonBeanConfig {
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1155,11 +1143,13 @@ class ConfigurationClassPostProcessorTests {
@@ -1155,11 +1143,13 @@ class ConfigurationClassPostProcessorTests {
@Configuration
static class StaticSingletonBeanConfig {
public static @Bean Foo foo ( ) {
@Bean
public static Foo foo ( ) {
return new Foo ( ) ;
}
public static @Bean Bar bar ( ) {
@Bean
public static Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1168,11 +1158,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1168,11 +1158,11 @@ class ConfigurationClassPostProcessorTests {
@Order ( 2 )
static class OverridingSingletonBeanConfig {
public @Bean ExtendedFoo foo ( ) {
@Bean public ExtendedFoo foo ( ) {
return new ExtendedFoo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1180,7 +1170,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1180,7 +1170,7 @@ class ConfigurationClassPostProcessorTests {
@Configuration
static class OverridingAgainSingletonBeanConfig {
public @Bean ExtendedAgainFoo foo ( ) {
@Bean public ExtendedAgainFoo foo ( ) {
return new ExtendedAgainFoo ( ) ;
}
}
@ -1188,7 +1178,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1188,7 +1178,7 @@ class ConfigurationClassPostProcessorTests {
@Configuration
static class InvalidOverridingSingletonBeanConfig {
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
}
@ -1200,11 +1190,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1200,11 +1190,11 @@ class ConfigurationClassPostProcessorTests {
@Order ( 1 )
static class SingletonBeanConfig {
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1213,11 +1203,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1213,11 +1203,11 @@ class ConfigurationClassPostProcessorTests {
@Order ( 2 )
static class OverridingSingletonBeanConfig {
public @Bean ExtendedFoo foo ( ) {
@Bean public ExtendedFoo foo ( ) {
return new ExtendedFoo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1233,11 +1223,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1233,11 +1223,11 @@ class ConfigurationClassPostProcessorTests {
public SingletonBeanConfig ( ConfigWithOrderedInnerClasses other ) {
}
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1250,11 +1240,11 @@ class ConfigurationClassPostProcessorTests {
@@ -1250,11 +1240,11 @@ class ConfigurationClassPostProcessorTests {
other . getObject ( ) ;
}
public @Bean ExtendedFoo foo ( ) {
@Bean public ExtendedFoo foo ( ) {
return new ExtendedFoo ( ) ;
}
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( foo ( ) ) ;
}
}
@ -1281,7 +1271,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1281,7 +1271,7 @@ class ConfigurationClassPostProcessorTests {
@Configuration
static class UnloadedConfig {
public @Bean Foo foo ( ) {
@Bean public Foo foo ( ) {
return new Foo ( ) ;
}
}
@ -1289,7 +1279,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1289,7 +1279,7 @@ class ConfigurationClassPostProcessorTests {
@Configuration
static class LoadedConfig {
public @Bean Bar bar ( ) {
@Bean public Bar bar ( ) {
return new Bar ( new Foo ( ) ) ;
}
}
@ -1598,7 +1588,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1598,7 +1588,7 @@ class ConfigurationClassPostProcessorTests {
public static class WildcardWithGenericExtendsConfiguration {
@Bean
public Repository < ? extends Object > genericRepo ( ) {
public Repository < ? > genericRepo ( ) {
return new Repository < String > ( ) ;
}
@ -1707,7 +1697,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1707,7 +1697,7 @@ class ConfigurationClassPostProcessorTests {
}
@Configuration
public static ab str act class AbstractConfig {
public ab str ac t stati c class AbstractConfig {
@Bean
public ServiceBean serviceBean ( ) {
@ -1758,7 +1748,6 @@ class ConfigurationClassPostProcessorTests {
@@ -1758,7 +1748,6 @@ class ConfigurationClassPostProcessorTests {
}
public interface DefaultMethodsConfig extends BaseDefaultMethods {
}
@Configuration
@ -1891,7 +1880,7 @@ class ConfigurationClassPostProcessorTests {
@@ -1891,7 +1880,7 @@ class ConfigurationClassPostProcessorTests {
}
}
static ab str act class FooFactory {
ab str ac t stati c class FooFactory {
abstract DependingFoo createFoo ( BarArgument bar ) ;
}
@ -2010,7 +1999,7 @@ class ConfigurationClassPostProcessorTests {
@@ -2010,7 +1999,7 @@ class ConfigurationClassPostProcessorTests {
}
@Configuration
static ab str act class BeanLookupConfiguration {
ab str ac t stati c class BeanLookupConfiguration {
@Bean
public TestBean thing ( ) {