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
bac10164
Commit
bac10164
authored
Apr 16, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
See gh-25532
parent
bd9dd9d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
33 deletions
+34
-33
MockConfigurationPropertySource.java
...xt/properties/source/MockConfigurationPropertySource.java
+1
-1
KotlinConstructorParametersBinderTests.kt
...properties/bind/KotlinConstructorParametersBinderTests.kt
+33
-32
No files found.
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/MockConfigurationPropertySource.java
View file @
bac10164
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
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/test/kotlin/org/springframework/boot/context/properties/bind/KotlinConstructorParametersBinderTests.kt
View file @
bac10164
...
...
@@ -17,16 +17,16 @@ class KotlinConstructorParametersBinderTests {
@Test
fun
`
Bind
to
class
should
create
bound
bean
`
()
{
val
source
=
MockConfigurationPropertySource
(
mapOf
(
"foo.int-value"
to
"12"
,
"foo.int-value"
to
"12"
,
"foo.long-value"
to
"34"
,
"foo.boolean-value"
to
"true"
,
"foo.string-value"
to
"foo"
,
"foo.enum-value"
to
"foo-bar"
))
"foo.int-value"
to
"12"
,
"foo.long-value"
to
"34"
,
"foo.boolean-value"
to
"true"
,
"foo.string-value"
to
"foo"
,
"foo.enum-value"
to
"foo-bar"
))
val
binder
=
Binder
(
source
)
val
bean
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ExampleValueBean
::
class
.
java
)).
get
()
assertThat
(
bean
.
intValue
).
isEqualTo
(
12
)
assertThat
(
bean
.
longValue
).
isEqualTo
(
34
)
assertThat
(
bean
.
booleanValue
).
isTrue
assertThat
(
bean
.
booleanValue
).
isTrue
()
assertThat
(
bean
.
stringValue
).
isEqualTo
(
"foo"
)
assertThat
(
bean
.
enumValue
).
isEqualTo
(
ExampleEnum
.
FOO_BAR
)
}
...
...
@@ -34,16 +34,16 @@ class KotlinConstructorParametersBinderTests {
@Test
fun
`
Bind
to
class
when
has
no
prefix
should
create
bound
bean
`
()
{
val
source
=
MockConfigurationPropertySource
(
mapOf
(
"int-value"
to
"12"
,
"long-value"
to
"34"
,
"boolean-value"
to
"true"
,
"string-value"
to
"foo"
,
"enum-value"
to
"foo-bar"
))
"long-value"
to
"34"
,
"boolean-value"
to
"true"
,
"string-value"
to
"foo"
,
"enum-value"
to
"foo-bar"
))
val
binder
=
Binder
(
source
)
val
bean
=
binder
.
bind
(
ConfigurationPropertyName
.
of
(
""
),
Bindable
.
of
(
ExampleValueBean
::
class
.
java
)).
get
()
assertThat
(
bean
.
intValue
).
isEqualTo
(
12
)
assertThat
(
bean
.
longValue
).
isEqualTo
(
34
)
assertThat
(
bean
.
booleanValue
).
isTrue
assertThat
(
bean
.
booleanValue
).
isTrue
()
assertThat
(
bean
.
stringValue
).
isEqualTo
(
"foo"
)
assertThat
(
bean
.
enumValue
).
isEqualTo
(
ExampleEnum
.
FOO_BAR
)
}
...
...
@@ -51,17 +51,17 @@ class KotlinConstructorParametersBinderTests {
@Test
fun
`
Bind
to
data class
should
create
bound
bean
`
()
{
val
source
=
MockConfigurationPropertySource
(
mapOf
(
"foo.int-value"
to
"12"
,
"foo.long-value"
to
"34"
,
"foo.boolean-value"
to
"true"
,
"foo.string-value"
to
"foo"
,
"foo.enum-value"
to
"foo-bar"
))
"foo.long-value"
to
"34"
,
"foo.boolean-value"
to
"true"
,
"foo.string-value"
to
"foo"
,
"foo.enum-value"
to
"foo-bar"
))
val
binder
=
Binder
(
source
)
val
bean
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ExampleDataClassBean
::
class
.
java
)).
get
()
val
expectedBean
=
ExampleDataClassBean
(
intValue
=
12
,
longValue
=
34
,
booleanValue
=
true
,
stringValue
=
"foo"
,
enumValue
=
ExampleEnum
.
FOO_BAR
)
longValue
=
34
,
booleanValue
=
true
,
stringValue
=
"foo"
,
enumValue
=
ExampleEnum
.
FOO_BAR
)
assertThat
(
bean
).
isEqualTo
(
expectedBean
)
}
...
...
@@ -71,7 +71,7 @@ class KotlinConstructorParametersBinderTests {
val
binder
=
Binder
(
source
)
val
bindable
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
MultipleConstructorsWithPrimaryConstructorBean
::
class
.
java
))
assertThat
(
bindable
.
isBound
).
isTrue
assertThat
(
bindable
.
isBound
).
isTrue
()
assertThat
(
bindable
.
get
().
intValue
).
isEqualTo
(
12
)
}
...
...
@@ -81,7 +81,7 @@ class KotlinConstructorParametersBinderTests {
val
binder
=
Binder
(
source
)
val
bindable
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
MultipleConstructorsBean
::
class
.
java
))
assertThat
(
bindable
.
isBound
).
isFalse
assertThat
(
bindable
.
isBound
).
isFalse
()
}
@Test
...
...
@@ -90,20 +90,20 @@ class KotlinConstructorParametersBinderTests {
val
binder
=
Binder
(
source
)
val
bindable
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
DefaultConstructorBean
::
class
.
java
))
assertThat
(
bindable
.
isBound
).
isFalse
assertThat
(
bindable
.
isBound
).
isFalse
()
}
@Test
fun
`
Bind
to
class
should
bind
nested
`
()
{
val
source
=
MockConfigurationPropertySource
(
mapOf
(
"foo.value-bean.int-value"
to
"123"
,
"foo.value-bean.long-value"
to
"34"
,
"foo.value-bean.boolean-value"
to
"true"
,
"foo.value-bean.string-value"
to
"foo"
))
"foo.value-bean.long-value"
to
"34"
,
"foo.value-bean.boolean-value"
to
"true"
,
"foo.value-bean.string-value"
to
"foo"
))
val
binder
=
Binder
(
source
)
val
bean
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ExampleNestedBean
::
class
.
java
)).
get
()
assertThat
(
bean
.
valueBean
.
intValue
).
isEqualTo
(
123
)
assertThat
(
bean
.
valueBean
.
longValue
).
isEqualTo
(
34
)
assertThat
(
bean
.
valueBean
.
booleanValue
).
isTrue
assertThat
(
bean
.
valueBean
.
booleanValue
).
isTrue
()
assertThat
(
bean
.
valueBean
.
stringValue
).
isEqualTo
(
"foo"
)
assertThat
(
bean
.
valueBean
.
enumValue
).
isNull
()
}
...
...
@@ -129,7 +129,7 @@ class KotlinConstructorParametersBinderTests {
ExamplePrimitiveDefaultBean
::
class
.
java
)).
get
()
assertThat
(
bean
.
intValue
).
isEqualTo
(
0
)
assertThat
(
bean
.
longValue
).
isEqualTo
(
0
)
assertThat
(
bean
.
booleanValue
).
isFalse
assertThat
(
bean
.
booleanValue
).
isFalse
()
assertThat
(
bean
.
stringValue
).
isEqualTo
(
"foo"
)
assertThat
(
bean
.
enumValue
).
isNull
()
}
...
...
@@ -139,7 +139,7 @@ class KotlinConstructorParametersBinderTests {
val
source
=
MockConfigurationPropertySource
(
"foo.string-value"
,
"foo"
)
val
binder
=
Binder
(
source
)
assertThat
(
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ExampleDefaultValueBean
::
class
.
java
)).
isBound
).
isFalse
ExampleDefaultValueBean
::
class
.
java
)).
isBound
).
isFalse
()
}
@Test
...
...
@@ -159,10 +159,10 @@ class KotlinConstructorParametersBinderTests {
val
binder
=
Binder
(
source
)
val
bean
=
binder
.
bind
(
"foo"
,
Bindable
.
of
(
ExampleDataClassBean
::
class
.
java
)).
get
()
val
expectedBean
=
ExampleDataClassBean
(
intValue
=
5
,
longValue
=
42
,
booleanValue
=
false
,
stringValue
=
"my data"
,
enumValue
=
ExampleEnum
.
FOO_BAR
)
longValue
=
42
,
booleanValue
=
false
,
stringValue
=
"my data"
,
enumValue
=
ExampleEnum
.
FOO_BAR
)
assertThat
(
bean
).
isEqualTo
(
expectedBean
)
}
...
...
@@ -244,4 +244,5 @@ class KotlinConstructorParametersBinderTests {
object
ExampleSingletonBean
{
var
stringValue
:
String
?
=
null
}
}
\ No newline at end of file
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