Commit 84901fa5 authored by Madhura Bhave's avatar Madhura Bhave

OnClassCondition report should only include relevant condition

Closes gh-11086
parent b03f8e4a
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment