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
ccf18001
Commit
ccf18001
authored
Jan 28, 2017
by
tinexw
Committed by
Stephane Nicoll
Apr 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle null value in OnExpressionCondition
Closes gh-2886
parent
70f57282
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
2 deletions
+85
-2
OnExpressionCondition.java
...k/boot/autoconfigure/condition/OnExpressionCondition.java
+3
-2
OnExpressionConditionTest.java
...ot/autoconfigure/condition/OnExpressionConditionTest.java
+82
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnExpressionCondition.java
View file @
ccf18001
...
@@ -51,8 +51,9 @@ class OnExpressionCondition extends SpringBootCondition {
...
@@ -51,8 +51,9 @@ class OnExpressionCondition extends SpringBootCondition {
if
(
resolver
==
null
)
{
if
(
resolver
==
null
)
{
resolver
=
new
StandardBeanExpressionResolver
();
resolver
=
new
StandardBeanExpressionResolver
();
}
}
boolean
result
=
(
Boolean
)
resolver
.
evaluate
(
expression
,
expressionContext
);
Object
result
=
resolver
.
evaluate
(
expression
,
expressionContext
);
return
new
ConditionOutcome
(
result
,
ConditionMessage
boolean
match
=
result
==
null
?
false
:
(
boolean
)
result
;
return
new
ConditionOutcome
(
match
,
ConditionMessage
.
forCondition
(
ConditionalOnExpression
.
class
,
"("
+
rawExpression
+
")"
)
.
forCondition
(
ConditionalOnExpression
.
class
,
"("
+
rawExpression
+
")"
)
.
resultedIn
(
result
));
.
resultedIn
(
result
));
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/OnExpressionConditionTest.java
0 → 100644
View file @
ccf18001
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
condition
;
import
java.util.Collections
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.springframework.beans.factory.config.BeanExpressionResolver
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
BDDMockito
.
when
;
/**
* Tests for the {@link OnExpressionCondition}.
*
* @author Kristine Jetzke
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
OnExpressionConditionTest
{
@Mock
private
ConditionContext
context
;
@Mock
private
AnnotatedTypeMetadata
metadata
;
@Mock
private
Environment
environment
;
@Mock
private
ConfigurableListableBeanFactory
beanFactory
;
@Mock
private
BeanExpressionResolver
resolver
;
@Before
public
void
setup
()
{
when
(
this
.
context
.
getEnvironment
()).
thenReturn
(
this
.
environment
);
when
(
this
.
environment
.
resolvePlaceholders
(
any
())).
thenReturn
(
"foo"
);
when
(
this
.
context
.
getBeanFactory
()).
thenReturn
(
this
.
beanFactory
);
when
(
this
.
beanFactory
.
getBeanExpressionResolver
()).
thenReturn
(
this
.
resolver
);
when
(
this
.
metadata
.
getAnnotationAttributes
(
any
()))
.
thenReturn
(
Collections
.
singletonMap
(
"value"
,
"bar"
));
}
@Test
public
void
nullShouldEvaluateToFalse
()
{
when
(
this
.
resolver
.
evaluate
(
any
(),
any
())).
thenReturn
(
null
);
OnExpressionCondition
condition
=
new
OnExpressionCondition
();
ConditionOutcome
conditionOutcome
=
condition
.
getMatchOutcome
(
this
.
context
,
this
.
metadata
);
assertThat
(
conditionOutcome
.
isMatch
()).
isFalse
();
}
}
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