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
2ccefbc2
Commit
2ccefbc2
authored
May 18, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify MapBinderTests
parent
84a38c56
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
34 deletions
+13
-34
MapBinderTests.java
...ramework/boot/context/properties/bind/MapBinderTests.java
+13
-34
No files found.
spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java
View file @
2ccefbc2
...
@@ -376,58 +376,37 @@ public class MapBinderTests {
...
@@ -376,58 +376,37 @@ public class MapBinderTests {
}
}
@Test
@Test
public
void
bindToMapNonScalarCollectionShould
TriggerOnSuccess
()
throws
Exception
{
public
void
bindToMapNonScalarCollectionShould
PopulateMap
()
throws
Exception
{
Bindable
<
List
<
JavaBean
>>
valueType
=
Bindable
.
listOf
(
JavaBean
.
class
);
Bindable
<
List
<
JavaBean
>>
valueType
=
Bindable
.
listOf
(
JavaBean
.
class
);
ResolvableType
mapType
=
ResolvableType
.
forClassWithGenerics
(
Map
.
class
,
ResolvableType
.
forClass
(
String
.
class
),
valueType
.
getType
());
Bindable
<
Map
<
String
,
List
<
JavaBean
>>>
target
=
getMapBindable
(
String
.
class
,
valueType
.
getType
());
Bindable
<
Map
<
String
,
List
<
JavaBean
>>>
target
=
Bindable
.
of
(
mapType
);
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
MockConfigurationPropertySource
source
=
new
MockConfigurationPropertySource
();
source
.
put
(
"foo.bar[0].value"
,
"a"
);
source
.
put
(
"foo.bar[0].value"
,
"a"
);
source
.
put
(
"foo.bar[1].value"
,
"b"
);
source
.
put
(
"foo.bar[1].value"
,
"b"
);
source
.
put
(
"foo.bar[2].value"
,
"c"
);
source
.
put
(
"foo.bar[2].value"
,
"c"
);
this
.
sources
this
.
sources
.
add
(
source
);
.
add
(
source
);
BindHandler
handler
=
mock
(
BindHandler
.
class
,
Map
<
String
,
List
<
JavaBean
>>
map
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
withSettings
().
defaultAnswer
(
Answers
.
CALLS_REAL_METHODS
));
List
<
String
>
values
=
map
.
get
(
"bar"
).
stream
().
map
(
JavaBean:
:
getValue
).
collect
(
Collectors
.
toList
());
this
.
binder
.
bind
(
"foo"
,
target
,
handler
);
assertThat
(
values
).
containsExactly
(
"a"
,
"b"
,
"c"
);
InOrder
inOrder
=
inOrder
(
handler
);
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo.bar[0].value"
)),
eq
(
Bindable
.
of
(
String
.
class
)),
any
(),
eq
(
"a"
));
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo.bar[1].value"
)),
eq
(
Bindable
.
of
(
String
.
class
)),
any
(),
eq
(
"b"
));
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo.bar[2].value"
)),
eq
(
Bindable
.
of
(
String
.
class
)),
any
(),
eq
(
"c"
));
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo"
)),
eq
(
target
),
any
(),
isA
(
Map
.
class
));
}
}
@Test
@Test
public
void
bindToPropertiesShouldBeEquivalentToMapOfStringString
()
throws
Exception
{
public
void
bindToPropertiesShouldBeEquivalentToMapOfStringString
()
throws
Exception
{
this
.
sources
this
.
sources
.
add
(
new
MockConfigurationPropertySource
(
"foo.bar.baz"
,
"1"
,
"line1"
));
.
add
(
new
MockConfigurationPropertySource
(
"foo.bar.baz"
,
"1"
,
"line1"
));
BindHandler
handler
=
mock
(
BindHandler
.
class
,
withSettings
().
defaultAnswer
(
Answers
.
CALLS_REAL_METHODS
));
Bindable
<
Properties
>
target
=
Bindable
.
of
(
Properties
.
class
);
Bindable
<
Properties
>
target
=
Bindable
.
of
(
Properties
.
class
);
this
.
binder
.
bind
(
"foo"
,
target
,
handler
);
Properties
properties
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
InOrder
inOrder
=
inOrder
(
handler
);
assertThat
(
properties
.
getProperty
(
"bar.baz"
)).
isEqualTo
(
"1"
);
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo.bar.baz"
)),
eq
(
Bindable
.
of
(
String
.
class
)),
any
(),
eq
(
"1"
));
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo"
)),
eq
(
target
),
any
(),
isA
(
Properties
.
class
));
}
}
@Test
@Test
public
void
bindToMapShouldNotTreatClassWithStringConstructorAsScalar
()
throws
Exception
{
public
void
bindToMapShouldNotTreatClassWithStringConstructorAsScalar
()
throws
Exception
{
this
.
sources
this
.
sources
.
add
(
new
MockConfigurationPropertySource
(
"foo.bar.pattern"
,
"1"
,
"line1"
));
.
add
(
new
MockConfigurationPropertySource
(
"foo.bar.pattern"
,
"1"
,
"line1"
));
BindHandler
handler
=
mock
(
BindHandler
.
class
,
Bindable
<
Map
<
String
,
Foo
>>
target
=
Bindable
.
mapOf
(
String
.
class
,
Foo
.
class
);
withSettings
().
defaultAnswer
(
Answers
.
CALLS_REAL_METHODS
));
Map
<
String
,
Foo
>
map
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
Bindable
<
Map
<
String
,
Foo
>>
target
=
Bindable
.
of
(
ResolvableType
.
forClassWithGenerics
(
Map
.
class
,
String
.
class
,
Foo
.
class
));
assertThat
(
map
.
get
(
"bar"
).
getPattern
()).
isEqualTo
(
"1"
);
this
.
binder
.
bind
(
"foo"
,
target
,
handler
);
InOrder
inOrder
=
inOrder
(
handler
);
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo.bar.pattern"
)),
eq
(
Bindable
.
of
(
String
.
class
)),
any
(),
eq
(
"1"
));
inOrder
.
verify
(
handler
).
onSuccess
(
eq
(
ConfigurationPropertyName
.
of
(
"foo"
)),
eq
(
target
),
any
(),
isA
(
Map
.
class
));
}
}
@Test
@Test
...
@@ -478,8 +457,8 @@ public class MapBinderTests {
...
@@ -478,8 +457,8 @@ public class MapBinderTests {
this
.
sources
this
.
sources
.
add
(
mockSource
);
.
add
(
mockSource
);
Map
<
String
,
List
<
JavaBean
>>
map
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
Map
<
String
,
List
<
JavaBean
>>
map
=
this
.
binder
.
bind
(
"foo"
,
target
).
get
();
List
<
JavaBean
>
values
=
map
.
get
(
"bar.baz"
);
List
<
String
>
values
=
map
.
get
(
"bar.baz"
).
stream
().
map
(
JavaBean:
:
getValue
).
collect
(
Collectors
.
toList
()
);
assertThat
(
values
.
stream
().
map
(
JavaBean:
:
getValue
).
collect
(
Collectors
.
toList
())
).
containsExactly
(
"a"
,
"b"
,
"c"
);
assertThat
(
values
).
containsExactly
(
"a"
,
"b"
,
"c"
);
}
}
@Test
@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