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
597fe237
Commit
597fe237
authored
Aug 22, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add PropertyMapper.from(value)"
Closes gh-13837
parent
1bd52bc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
26 deletions
+24
-26
BasicBatchConfigurer.java
...mework/boot/autoconfigure/batch/BasicBatchConfigurer.java
+1
-1
PropertyMapper.java
...ringframework/boot/context/properties/PropertyMapper.java
+12
-12
PropertyMapperTests.java
...ramework/boot/context/properties/PropertyMapperTests.java
+11
-13
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java
View file @
597fe237
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java
View file @
597fe237
...
...
@@ -91,24 +91,13 @@ public final class PropertyMapper {
return
new
PropertyMapper
(
this
,
operator
);
}
/**
* Return a new {@link Source} from the specified value that can be used to perform
* the mapping.
* @param <T> the source type
* @param value the value
* @return a {@link Source} that can be used to complete the mapping
* @see #from(Supplier)
*/
public
<
T
>
Source
<
T
>
from
(
T
value
)
{
return
from
(()
->
value
);
}
/**
* Return a new {@link Source} from the specified value supplier that can be used to
* perform the mapping.
* @param <T> the source type
* @param supplier the value supplier
* @return a {@link Source} that can be used to complete the mapping
* @see #from(Object)
*/
public
<
T
>
Source
<
T
>
from
(
Supplier
<
T
>
supplier
)
{
Assert
.
notNull
(
supplier
,
"Supplier must not be null"
);
...
...
@@ -119,6 +108,17 @@ public final class PropertyMapper {
return
source
;
}
/**
* Return a new {@link Source} from the specified value that can be used to perform
* the mapping.
* @param <T> the source type
* @param value the value
* @return a {@link Source} that can be used to complete the mapping
*/
public
<
T
>
Source
<
T
>
from
(
T
value
)
{
return
from
(()
->
value
);
}
@SuppressWarnings
(
"unchecked"
)
private
<
T
>
Source
<
T
>
getSource
(
Supplier
<
T
>
supplier
)
{
if
(
this
.
parent
!=
null
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java
View file @
597fe237
...
...
@@ -120,24 +120,24 @@ public class PropertyMapperTests {
@Test
public
void
whenTrueWhenValueIsTrueShouldMap
()
{
Boolean
result
=
this
.
map
.
from
(
()
->
true
).
whenTrue
().
toInstance
(
Boolean:
:
new
);
Boolean
result
=
this
.
map
.
from
(
true
).
whenTrue
().
toInstance
(
Boolean:
:
new
);
assertThat
(
result
).
isTrue
();
}
@Test
public
void
whenTrueWhenValueIsFalseShouldNotMap
()
{
this
.
map
.
from
(
()
->
false
).
whenTrue
().
toCall
(
Assert:
:
fail
);
this
.
map
.
from
(
false
).
whenTrue
().
toCall
(
Assert:
:
fail
);
}
@Test
public
void
whenFalseWhenValueIsFalseShouldMap
()
{
Boolean
result
=
this
.
map
.
from
(
()
->
false
).
whenFalse
().
toInstance
(
Boolean:
:
new
);
Boolean
result
=
this
.
map
.
from
(
false
).
whenFalse
().
toInstance
(
Boolean:
:
new
);
assertThat
(
result
).
isFalse
();
}
@Test
public
void
whenFalseWhenValueIsTrueShouldNotMap
()
{
this
.
map
.
from
(
()
->
true
).
whenFalse
().
toCall
(
Assert:
:
fail
);
this
.
map
.
from
(
true
).
whenFalse
().
toCall
(
Assert:
:
fail
);
}
@Test
...
...
@@ -147,30 +147,29 @@ public class PropertyMapperTests {
@Test
public
void
whenHasTextWhenValueIsEmptyShouldNotMap
()
{
this
.
map
.
from
(
()
->
""
).
whenHasText
().
toCall
(
Assert:
:
fail
);
this
.
map
.
from
(
""
).
whenHasText
().
toCall
(
Assert:
:
fail
);
}
@Test
public
void
whenHasTextWhenValueHasTextShouldMap
()
{
Integer
result
=
this
.
map
.
from
(
()
->
123
).
whenHasText
().
toInstance
(
Integer:
:
new
);
Integer
result
=
this
.
map
.
from
(
123
).
whenHasText
().
toInstance
(
Integer:
:
new
);
assertThat
(
result
).
isEqualTo
(
123
);
}
@Test
public
void
whenEqualToWhenValueIsEqualShouldMatch
()
{
String
result
=
this
.
map
.
from
(()
->
"123"
).
whenEqualTo
(
"123"
)
.
toInstance
(
String:
:
new
);
String
result
=
this
.
map
.
from
(
"123"
).
whenEqualTo
(
"123"
).
toInstance
(
String:
:
new
);
assertThat
(
result
).
isEqualTo
(
"123"
);
}
@Test
public
void
whenEqualToWhenValueIsNotEqualShouldNotMatch
()
{
this
.
map
.
from
(
()
->
"123"
).
whenEqualTo
(
"321"
).
toCall
(
Assert:
:
fail
);
this
.
map
.
from
(
"123"
).
whenEqualTo
(
"321"
).
toCall
(
Assert:
:
fail
);
}
@Test
public
void
whenInstanceOfWhenValueIsTargetTypeShouldMatch
()
{
Long
result
=
this
.
map
.
from
(
()
->
123L
).
whenInstanceOf
(
Long
.
class
)
Long
result
=
this
.
map
.
from
(
123L
).
whenInstanceOf
(
Long
.
class
)
.
toInstance
((
value
)
->
value
+
1
);
assertThat
(
result
).
isEqualTo
(
124L
);
}
...
...
@@ -183,14 +182,13 @@ public class PropertyMapperTests {
@Test
public
void
whenWhenValueMatchesShouldMap
()
{
String
result
=
this
.
map
.
from
(()
->
"123"
).
when
(
"123"
::
equals
)
.
toInstance
(
String:
:
new
);
String
result
=
this
.
map
.
from
(
"123"
).
when
(
"123"
::
equals
).
toInstance
(
String:
:
new
);
assertThat
(
result
).
isEqualTo
(
"123"
);
}
@Test
public
void
whenWhenValueDoesNotMatchShouldNotMap
()
{
this
.
map
.
from
(
()
->
"123"
).
when
(
"321"
::
equals
).
toCall
(
Assert:
:
fail
);
this
.
map
.
from
(
"123"
).
when
(
"321"
::
equals
).
toCall
(
Assert:
:
fail
);
}
@Test
...
...
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