Skip to content

Commit

Permalink
Fix condition source in OnBeanCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Cordoba authored and snicoll committed Feb 11, 2020
1 parent d485708 commit 547fc30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* @author Jakub Kubrynski
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Jorge Cordoba
* @see ConditionalOnBean
* @see ConditionalOnMissingBean
* @see ConditionalOnSingleCandidate
Expand Down Expand Up @@ -387,7 +388,7 @@ private static class Spec<A extends Annotation> {

private final ClassLoader classLoader;

private final Class<?> annotationType;
private final Class<? extends Annotation> annotationType;

private final Set<String> names;

Expand Down Expand Up @@ -581,11 +582,11 @@ Set<Class<?>> getParameterizedContainers() {
}

ConditionMessage.Builder message() {
return ConditionMessage.forCondition(ConditionalOnBean.class, this);
return ConditionMessage.forCondition(this.annotationType, this);
}

ConditionMessage.Builder message(ConditionMessage message) {
return message.andCondition(ConditionalOnBean.class, this);
return message.andCondition(this.annotationType, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collection;
import java.util.Date;
import java.util.function.Consumer;

Expand Down Expand Up @@ -57,6 +58,7 @@
* @author Phillip Webb
* @author Jakub Kubrynski
* @author Andy Wilkinson
* @author Jorge Cordoba
*/
@SuppressWarnings("resource")
public class ConditionalOnMissingBeanTests {
Expand Down Expand Up @@ -135,6 +137,16 @@ void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
assertThat(context.getBean("foo")).isEqualTo("foo");
});
}
@Test
void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage() {
this.contextRunner.withUserConfiguration(ConditionalOnMissingBeanTests.OnBeanNameConfiguration.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("@ConditionalOnBean (names: foo; SearchStrategy: all) did not find any beans");
});
}

@Test
void testOnMissingBeanConditionWithFactoryBean() {
Expand Down

0 comments on commit 547fc30

Please sign in to comment.