|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 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.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.condition;
|
18 | 18 |
|
| 19 | +import java.time.Duration; |
19 | 20 | import java.util.Iterator;
|
20 | 21 | import java.util.Map;
|
21 | 22 |
|
|
27 | 28 |
|
28 | 29 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
29 | 30 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
| 31 | +import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 32 | +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
30 | 33 | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcome;
|
31 | 34 | import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes;
|
32 | 35 | import org.springframework.boot.autoconfigure.condition.config.UniqueShortNameAutoConfiguration;
|
33 | 36 | import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
34 |
| -import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; |
35 |
| -import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; |
36 | 37 | import org.springframework.boot.test.util.TestPropertyValues;
|
37 | 38 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
38 | 39 | import org.springframework.context.annotation.Bean;
|
|
41 | 42 | import org.springframework.context.annotation.Conditional;
|
42 | 43 | import org.springframework.context.annotation.Configuration;
|
43 | 44 | import org.springframework.context.annotation.ConfigurationCondition;
|
44 |
| -import org.springframework.context.annotation.Import; |
45 | 45 | import org.springframework.core.type.AnnotatedTypeMetadata;
|
46 | 46 | import org.springframework.util.ClassUtils;
|
47 | 47 |
|
@@ -163,7 +163,17 @@ private void prepareMatches(boolean m1, boolean m2, boolean m3) {
|
163 | 163 | void springBootConditionPopulatesReport() {
|
164 | 164 | ConditionEvaluationReport report = ConditionEvaluationReport
|
165 | 165 | .get(new AnnotationConfigApplicationContext(Config.class).getBeanFactory());
|
166 |
| - assertThat(report.getConditionAndOutcomesBySource()).isNotEmpty(); |
| 166 | + assertThat(report.getUnconditionalClasses()).containsExactly(UnconditionalAutoConfiguration.class.getName()); |
| 167 | + assertThat(report.getConditionAndOutcomesBySource()).containsOnlyKeys(MatchingAutoConfiguration.class.getName(), |
| 168 | + NonMatchingAutoConfiguration.class.getName()); |
| 169 | + assertThat(report.getConditionAndOutcomesBySource().get(MatchingAutoConfiguration.class.getName())) |
| 170 | + .satisfies((outcomes) -> assertThat(outcomes).extracting(ConditionAndOutcome::getOutcome) |
| 171 | + .extracting(ConditionOutcome::isMatch) |
| 172 | + .containsOnly(true)); |
| 173 | + assertThat(report.getConditionAndOutcomesBySource().get(NonMatchingAutoConfiguration.class.getName())) |
| 174 | + .satisfies((outcomes) -> assertThat(outcomes).extracting(ConditionAndOutcome::getOutcome) |
| 175 | + .extracting(ConditionOutcome::isMatch) |
| 176 | + .containsOnly(false)); |
167 | 177 | }
|
168 | 178 |
|
169 | 179 | @Test
|
@@ -230,18 +240,6 @@ void reportMessageWhenSameShortNamePresentMoreThanOnceShouldUseFullyQualifiedNam
|
230 | 240 | context.close();
|
231 | 241 | }
|
232 | 242 |
|
233 |
| - @Configuration(proxyBeanMethods = false) |
234 |
| - @Import(WebMvcAutoConfiguration.class) |
235 |
| - static class Config { |
236 |
| - |
237 |
| - } |
238 |
| - |
239 |
| - @Configuration(proxyBeanMethods = false) |
240 |
| - @Import(MultipartAutoConfiguration.class) |
241 |
| - static class DuplicateConfig { |
242 |
| - |
243 |
| - } |
244 |
| - |
245 | 243 | @Configuration(proxyBeanMethods = false)
|
246 | 244 | @Conditional({ ConditionEvaluationReportTests.MatchParseCondition.class,
|
247 | 245 | ConditionEvaluationReportTests.NoMatchBeanCondition.class })
|
@@ -315,4 +313,33 @@ static class NoMatchBeanCondition extends TestMatchCondition {
|
315 | 313 |
|
316 | 314 | }
|
317 | 315 |
|
| 316 | + @Configuration(proxyBeanMethods = false) |
| 317 | + @ImportAutoConfiguration({ MatchingAutoConfiguration.class, NonMatchingAutoConfiguration.class, |
| 318 | + UnconditionalAutoConfiguration.class }) |
| 319 | + static class Config { |
| 320 | + |
| 321 | + } |
| 322 | + |
| 323 | + @AutoConfiguration |
| 324 | + @ConditionalOnProperty(name = "com.example.property", matchIfMissing = true) |
| 325 | + static class MatchingAutoConfiguration { |
| 326 | + |
| 327 | + } |
| 328 | + |
| 329 | + @AutoConfiguration |
| 330 | + @ConditionalOnBean(Duration.class) |
| 331 | + static class NonMatchingAutoConfiguration { |
| 332 | + |
| 333 | + } |
| 334 | + |
| 335 | + @AutoConfiguration |
| 336 | + static class UnconditionalAutoConfiguration { |
| 337 | + |
| 338 | + @Bean |
| 339 | + String example() { |
| 340 | + return "example"; |
| 341 | + } |
| 342 | + |
| 343 | + } |
| 344 | + |
318 | 345 | }
|
0 commit comments