|
24 | 24 | import org.junit.jupiter.api.Test;
|
25 | 25 |
|
26 | 26 | import org.springframework.beans.factory.BeanDefinitionStoreException;
|
| 27 | +import org.springframework.beans.factory.annotation.Autowired; |
27 | 28 | import org.springframework.boot.context.annotation.UserConfigurations;
|
| 29 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 30 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
28 | 31 | import org.springframework.boot.test.context.FilteredClassLoader;
|
29 | 32 | import org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider;
|
30 | 33 | import org.springframework.context.ConfigurableApplicationContext;
|
|
33 | 36 | import org.springframework.context.annotation.ConditionContext;
|
34 | 37 | import org.springframework.context.annotation.Conditional;
|
35 | 38 | import org.springframework.context.annotation.Configuration;
|
| 39 | +import org.springframework.context.annotation.Lazy; |
36 | 40 | import org.springframework.core.env.Environment;
|
37 | 41 | import org.springframework.core.type.AnnotatedTypeMetadata;
|
38 | 42 | import org.springframework.util.ClassUtils;
|
@@ -165,6 +169,15 @@ void runWithClassLoaderShouldSetClassLoaderOnConditionContext() {
|
165 | 169 | .run((context) -> assertThat(context).hasSingleBean(ConditionalConfig.class));
|
166 | 170 | }
|
167 | 171 |
|
| 172 | + @Test |
| 173 | + void consecutiveRunWithFilteredClassLoaderShouldHaveBeanWithLazyProperties() { |
| 174 | + get().withClassLoader(new FilteredClassLoader(Gson.class)).withUserConfiguration(LazyConfig.class) |
| 175 | + .run((context) -> assertThat(context).hasSingleBean(ExampleBeanWithLazyProperties.class)); |
| 176 | + |
| 177 | + get().withClassLoader(new FilteredClassLoader(Gson.class)).withUserConfiguration(LazyConfig.class) |
| 178 | + .run((context) -> assertThat(context).hasSingleBean(ExampleBeanWithLazyProperties.class)); |
| 179 | + } |
| 180 | + |
168 | 181 | @Test
|
169 | 182 | void thrownRuleWorksWithCheckedException() {
|
170 | 183 | get().run((context) -> assertThatIOException().isThrownBy(() -> throwCheckedException("Expected message"))
|
@@ -241,6 +254,30 @@ static class ConditionalConfig {
|
241 | 254 |
|
242 | 255 | }
|
243 | 256 |
|
| 257 | + @Configuration(proxyBeanMethods = false) |
| 258 | + @EnableConfigurationProperties(ExampleProperties.class) |
| 259 | + static class LazyConfig { |
| 260 | + |
| 261 | + @Bean |
| 262 | + ExampleBeanWithLazyProperties exampleBeanWithLazyProperties() { |
| 263 | + return new ExampleBeanWithLazyProperties(); |
| 264 | + } |
| 265 | + |
| 266 | + } |
| 267 | + |
| 268 | + static class ExampleBeanWithLazyProperties { |
| 269 | + |
| 270 | + @Autowired |
| 271 | + @Lazy |
| 272 | + ExampleProperties exampleProperties; |
| 273 | + |
| 274 | + } |
| 275 | + |
| 276 | + @ConfigurationProperties |
| 277 | + public static class ExampleProperties { |
| 278 | + |
| 279 | + } |
| 280 | + |
244 | 281 | static class FilteredClassLoaderCondition implements Condition {
|
245 | 282 |
|
246 | 283 | @Override
|
|
0 commit comments