Commit bac10164 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish contribution

See gh-25532
parent bd9dd9d5
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -17,16 +17,16 @@ class KotlinConstructorParametersBinderTests { ...@@ -17,16 +17,16 @@ class KotlinConstructorParametersBinderTests {
@Test @Test
fun `Bind to class should create bound bean`() { fun `Bind to class should create bound bean`() {
val source = MockConfigurationPropertySource(mapOf("foo.int-value" to "12", val source = MockConfigurationPropertySource(mapOf("foo.int-value" to "12",
"foo.int-value" to "12", "foo.int-value" to "12",
"foo.long-value" to "34", "foo.long-value" to "34",
"foo.boolean-value" to "true", "foo.boolean-value" to "true",
"foo.string-value" to "foo", "foo.string-value" to "foo",
"foo.enum-value" to "foo-bar")) "foo.enum-value" to "foo-bar"))
val binder = Binder(source) val binder = Binder(source)
val bean = binder.bind("foo", Bindable.of(ExampleValueBean::class.java)).get() val bean = binder.bind("foo", Bindable.of(ExampleValueBean::class.java)).get()
assertThat(bean.intValue).isEqualTo(12) assertThat(bean.intValue).isEqualTo(12)
assertThat(bean.longValue).isEqualTo(34) assertThat(bean.longValue).isEqualTo(34)
assertThat(bean.booleanValue).isTrue assertThat(bean.booleanValue).isTrue()
assertThat(bean.stringValue).isEqualTo("foo") assertThat(bean.stringValue).isEqualTo("foo")
assertThat(bean.enumValue).isEqualTo(ExampleEnum.FOO_BAR) assertThat(bean.enumValue).isEqualTo(ExampleEnum.FOO_BAR)
} }
...@@ -34,16 +34,16 @@ class KotlinConstructorParametersBinderTests { ...@@ -34,16 +34,16 @@ class KotlinConstructorParametersBinderTests {
@Test @Test
fun `Bind to class when has no prefix should create bound bean`() { fun `Bind to class when has no prefix should create bound bean`() {
val source = MockConfigurationPropertySource(mapOf("int-value" to "12", val source = MockConfigurationPropertySource(mapOf("int-value" to "12",
"long-value" to "34", "long-value" to "34",
"boolean-value" to "true", "boolean-value" to "true",
"string-value" to "foo", "string-value" to "foo",
"enum-value" to "foo-bar")) "enum-value" to "foo-bar"))
val binder = Binder(source) val binder = Binder(source)
val bean = binder.bind(ConfigurationPropertyName.of(""), val bean = binder.bind(ConfigurationPropertyName.of(""),
Bindable.of(ExampleValueBean::class.java)).get() Bindable.of(ExampleValueBean::class.java)).get()
assertThat(bean.intValue).isEqualTo(12) assertThat(bean.intValue).isEqualTo(12)
assertThat(bean.longValue).isEqualTo(34) assertThat(bean.longValue).isEqualTo(34)
assertThat(bean.booleanValue).isTrue assertThat(bean.booleanValue).isTrue()
assertThat(bean.stringValue).isEqualTo("foo") assertThat(bean.stringValue).isEqualTo("foo")
assertThat(bean.enumValue).isEqualTo(ExampleEnum.FOO_BAR) assertThat(bean.enumValue).isEqualTo(ExampleEnum.FOO_BAR)
} }
...@@ -51,17 +51,17 @@ class KotlinConstructorParametersBinderTests { ...@@ -51,17 +51,17 @@ class KotlinConstructorParametersBinderTests {
@Test @Test
fun `Bind to data class should create bound bean`() { fun `Bind to data class should create bound bean`() {
val source = MockConfigurationPropertySource(mapOf("foo.int-value" to "12", val source = MockConfigurationPropertySource(mapOf("foo.int-value" to "12",
"foo.long-value" to "34", "foo.long-value" to "34",
"foo.boolean-value" to "true", "foo.boolean-value" to "true",
"foo.string-value" to "foo", "foo.string-value" to "foo",
"foo.enum-value" to "foo-bar")) "foo.enum-value" to "foo-bar"))
val binder = Binder(source) val binder = Binder(source)
val bean = binder.bind("foo", Bindable.of(ExampleDataClassBean::class.java)).get() val bean = binder.bind("foo", Bindable.of(ExampleDataClassBean::class.java)).get()
val expectedBean = ExampleDataClassBean(intValue = 12, val expectedBean = ExampleDataClassBean(intValue = 12,
longValue = 34, longValue = 34,
booleanValue = true, booleanValue = true,
stringValue = "foo", stringValue = "foo",
enumValue = ExampleEnum.FOO_BAR) enumValue = ExampleEnum.FOO_BAR)
assertThat(bean).isEqualTo(expectedBean) assertThat(bean).isEqualTo(expectedBean)
} }
...@@ -71,7 +71,7 @@ class KotlinConstructorParametersBinderTests { ...@@ -71,7 +71,7 @@ class KotlinConstructorParametersBinderTests {
val binder = Binder(source) val binder = Binder(source)
val bindable = binder.bind("foo", Bindable.of( val bindable = binder.bind("foo", Bindable.of(
MultipleConstructorsWithPrimaryConstructorBean::class.java)) MultipleConstructorsWithPrimaryConstructorBean::class.java))
assertThat(bindable.isBound).isTrue assertThat(bindable.isBound).isTrue()
assertThat(bindable.get().intValue).isEqualTo(12) assertThat(bindable.get().intValue).isEqualTo(12)
} }
...@@ -81,7 +81,7 @@ class KotlinConstructorParametersBinderTests { ...@@ -81,7 +81,7 @@ class KotlinConstructorParametersBinderTests {
val binder = Binder(source) val binder = Binder(source)
val bindable = binder.bind("foo", Bindable.of( val bindable = binder.bind("foo", Bindable.of(
MultipleConstructorsBean::class.java)) MultipleConstructorsBean::class.java))
assertThat(bindable.isBound).isFalse assertThat(bindable.isBound).isFalse()
} }
@Test @Test
...@@ -90,20 +90,20 @@ class KotlinConstructorParametersBinderTests { ...@@ -90,20 +90,20 @@ class KotlinConstructorParametersBinderTests {
val binder = Binder(source) val binder = Binder(source)
val bindable = binder.bind("foo", Bindable.of( val bindable = binder.bind("foo", Bindable.of(
DefaultConstructorBean::class.java)) DefaultConstructorBean::class.java))
assertThat(bindable.isBound).isFalse assertThat(bindable.isBound).isFalse()
} }
@Test @Test
fun `Bind to class should bind nested`() { fun `Bind to class should bind nested`() {
val source = MockConfigurationPropertySource(mapOf("foo.value-bean.int-value" to "123", val source = MockConfigurationPropertySource(mapOf("foo.value-bean.int-value" to "123",
"foo.value-bean.long-value" to "34", "foo.value-bean.long-value" to "34",
"foo.value-bean.boolean-value" to "true", "foo.value-bean.boolean-value" to "true",
"foo.value-bean.string-value" to "foo")) "foo.value-bean.string-value" to "foo"))
val binder = Binder(source) val binder = Binder(source)
val bean = binder.bind("foo", Bindable.of(ExampleNestedBean::class.java)).get() val bean = binder.bind("foo", Bindable.of(ExampleNestedBean::class.java)).get()
assertThat(bean.valueBean.intValue).isEqualTo(123) assertThat(bean.valueBean.intValue).isEqualTo(123)
assertThat(bean.valueBean.longValue).isEqualTo(34) 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.stringValue).isEqualTo("foo")
assertThat(bean.valueBean.enumValue).isNull() assertThat(bean.valueBean.enumValue).isNull()
} }
...@@ -129,7 +129,7 @@ class KotlinConstructorParametersBinderTests { ...@@ -129,7 +129,7 @@ class KotlinConstructorParametersBinderTests {
ExamplePrimitiveDefaultBean::class.java)).get() ExamplePrimitiveDefaultBean::class.java)).get()
assertThat(bean.intValue).isEqualTo(0) assertThat(bean.intValue).isEqualTo(0)
assertThat(bean.longValue).isEqualTo(0) assertThat(bean.longValue).isEqualTo(0)
assertThat(bean.booleanValue).isFalse assertThat(bean.booleanValue).isFalse()
assertThat(bean.stringValue).isEqualTo("foo") assertThat(bean.stringValue).isEqualTo("foo")
assertThat(bean.enumValue).isNull() assertThat(bean.enumValue).isNull()
} }
...@@ -139,7 +139,7 @@ class KotlinConstructorParametersBinderTests { ...@@ -139,7 +139,7 @@ class KotlinConstructorParametersBinderTests {
val source = MockConfigurationPropertySource("foo.string-value", "foo") val source = MockConfigurationPropertySource("foo.string-value", "foo")
val binder = Binder(source) val binder = Binder(source)
assertThat(binder.bind("foo", Bindable.of( assertThat(binder.bind("foo", Bindable.of(
ExampleDefaultValueBean::class.java)).isBound).isFalse ExampleDefaultValueBean::class.java)).isBound).isFalse()
} }
@Test @Test
...@@ -159,10 +159,10 @@ class KotlinConstructorParametersBinderTests { ...@@ -159,10 +159,10 @@ class KotlinConstructorParametersBinderTests {
val binder = Binder(source) val binder = Binder(source)
val bean = binder.bind("foo", Bindable.of(ExampleDataClassBean::class.java)).get() val bean = binder.bind("foo", Bindable.of(ExampleDataClassBean::class.java)).get()
val expectedBean = ExampleDataClassBean(intValue = 5, val expectedBean = ExampleDataClassBean(intValue = 5,
longValue = 42, longValue = 42,
booleanValue = false, booleanValue = false,
stringValue = "my data", stringValue = "my data",
enumValue = ExampleEnum.FOO_BAR) enumValue = ExampleEnum.FOO_BAR)
assertThat(bean).isEqualTo(expectedBean) assertThat(bean).isEqualTo(expectedBean)
} }
...@@ -244,4 +244,5 @@ class KotlinConstructorParametersBinderTests { ...@@ -244,4 +244,5 @@ class KotlinConstructorParametersBinderTests {
object ExampleSingletonBean { object ExampleSingletonBean {
var stringValue: String? = null var stringValue: String? = null
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment