Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
66809c6c
Commit
66809c6c
authored
Feb 11, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Fix condition source in OnBeanCondition"
See gh-19948
parent
547fc30e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
OnBeanCondition.java
...amework/boot/autoconfigure/condition/OnBeanCondition.java
+1
-2
ConditionalOnBeanTests.java
.../boot/autoconfigure/condition/ConditionalOnBeanTests.java
+13
-0
ConditionalOnMissingBeanTests.java
...utoconfigure/condition/ConditionalOnMissingBeanTests.java
+4
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java
View file @
66809c6c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -67,7 +67,6 @@ import org.springframework.util.StringUtils;
* @author Jakub Kubrynski
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Jorge Cordoba
* @see ConditionalOnBean
* @see ConditionalOnMissingBean
* @see ConditionalOnSingleCandidate
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java
View file @
66809c6c
...
...
@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType;
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
;
...
...
@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.ConditionAndOutcomes
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -134,6 +136,17 @@ class ConditionalOnBeanTests {
assertThat
(
context
.
getBean
(
"bar"
)).
isEqualTo
(
"bar"
);
}
@Test
void
onBeanConditionOutputShouldNotContainConditionalOnMissingBeanClassInMessage
()
{
this
.
contextRunner
.
withUserConfiguration
(
OnBeanNameConfiguration
.
class
).
run
((
context
)
->
{
Collection
<
ConditionAndOutcomes
>
conditionAndOutcomes
=
ConditionEvaluationReport
.
get
(
context
.
getSourceApplicationContext
().
getBeanFactory
()).
getConditionAndOutcomesBySource
()
.
values
();
String
message
=
conditionAndOutcomes
.
iterator
().
next
().
iterator
().
next
().
getOutcome
().
getMessage
();
assertThat
(
message
).
doesNotContain
(
"@ConditionalOnMissingBean"
);
});
}
@Test
void
conditionEvaluationConsidersChangeInTypeWhenBeanIsOverridden
()
{
this
.
contextRunner
.
withUserConfiguration
(
OriginalDefinition
.
class
,
OverridingDefinition
.
class
,
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java
View file @
66809c6c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -58,7 +58,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb
* @author Jakub Kubrynski
* @author Andy Wilkinson
* @author Jorge Cordoba
*/
@SuppressWarnings
(
"resource"
)
public
class
ConditionalOnMissingBeanTests
{
...
...
@@ -137,14 +136,15 @@ public class ConditionalOnMissingBeanTests {
assertThat
(
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
});
}
@Test
void
testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMessage
()
{
this
.
contextRunner
.
withUserConfiguration
(
ConditionalOnMissingBeanTests
.
OnBeanNameConfiguration
.
class
).
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
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
"
);
assertThat
(
message
).
doesNotContain
(
"@ConditionalOnBean"
);
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment