OnClassCondition report should only include relevant condition
Closes gh-11086
This commit is contained in:
parent
b03f8e4a4a
commit
84901fa58e
|
|
@ -158,7 +158,7 @@ class OnClassCondition extends SpringBootCondition
|
|||
MultiValueMap<String, Object> attributes = metadata
|
||||
.getAllAnnotationAttributes(annotationType.getName(), true);
|
||||
if (attributes == null) {
|
||||
return Collections.emptyList();
|
||||
return null;
|
||||
}
|
||||
List<String> candidates = new ArrayList<>();
|
||||
addAll(candidates, attributes.get("value"));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.condition;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
|
|
@ -68,6 +70,20 @@ public class ConditionalOnClassTests {
|
|||
.run(this::hasBarBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClassConditionOutputShouldNotContainConditionalOnMissingClassInMessage() {
|
||||
this.contextRunner.withUserConfiguration(BasicConfiguration.class)
|
||||
.run((context) -> {
|
||||
Collection<ConditionEvaluationReport.ConditionAndOutcomes> conditionAndOutcomes = ConditionEvaluationReport
|
||||
.get(context.getSourceApplicationContext().getBeanFactory())
|
||||
.getConditionAndOutcomesBySource().values();
|
||||
String message = conditionAndOutcomes.iterator().next().iterator()
|
||||
.next().getOutcome().getMessage();
|
||||
assertThat(message).doesNotContain(
|
||||
"@ConditionalOnMissingClass did not find unwanted class");
|
||||
});
|
||||
}
|
||||
|
||||
private void hasBarBean(AssertableApplicationContext context) {
|
||||
assertThat(context).hasBean("bar");
|
||||
assertThat(context.getBean("bar")).isEqualTo("bar");
|
||||
|
|
|
|||
Loading…
Reference in New Issue