Broaden test coverage for property binding with `@Name`
Closes gh-41588
This commit is contained in:
parent
9bb0c45ddb
commit
72867a3b25
|
@ -369,15 +369,25 @@ class ValueObjectBinderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void bindToAnnotationNamedParameter() {
|
||||
void bindToAnnotationNamedConstructorParameter() {
|
||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||
source.put("test.import", "test");
|
||||
this.sources.add(source);
|
||||
Bindable<NamedParameter> target = Bindable.of(NamedParameter.class);
|
||||
NamedParameter bound = this.binder.bindOrCreate("test", target);
|
||||
Bindable<NamedConstructorParameter> target = Bindable.of(NamedConstructorParameter.class);
|
||||
NamedConstructorParameter bound = this.binder.bindOrCreate("test", target);
|
||||
assertThat(bound.getImportName()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindToAnnotationNamedRecordComponent() {
|
||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||
source.put("test.import", "test");
|
||||
this.sources.add(source);
|
||||
Bindable<NamedRecordComponent> target = Bindable.of(NamedRecordComponent.class);
|
||||
NamedRecordComponent bound = this.binder.bindOrCreate("test", target);
|
||||
assertThat(bound.importName()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindToRecordWithDefaultValue() {
|
||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||
|
@ -886,11 +896,11 @@ class ValueObjectBinderTests {
|
|||
|
||||
}
|
||||
|
||||
static class NamedParameter {
|
||||
static class NamedConstructorParameter {
|
||||
|
||||
private final String importName;
|
||||
|
||||
NamedParameter(@Name("import") String importName) {
|
||||
NamedConstructorParameter(@Name("import") String importName) {
|
||||
this.importName = importName;
|
||||
}
|
||||
|
||||
|
@ -900,6 +910,9 @@ class ValueObjectBinderTests {
|
|||
|
||||
}
|
||||
|
||||
record NamedRecordComponent(@Name("import") String importName) {
|
||||
}
|
||||
|
||||
static class NonExtractableParameterName {
|
||||
|
||||
private String value;
|
||||
|
|
|
@ -179,10 +179,18 @@ class KotlinConstructorParametersBinderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `Bind to named constructor parameter`() {
|
||||
fun `Bind to named data class constructor parameter`() {
|
||||
val source = MockConfigurationPropertySource("foo.string-value", "test")
|
||||
val binder = Binder(source)
|
||||
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterBean::class.java)).get()
|
||||
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterDataClass::class.java)).get()
|
||||
assertThat(bean.stringDataValue).isEqualTo("test")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Bind to named class constructor parameter`() {
|
||||
val source = MockConfigurationPropertySource("foo.string-value", "test")
|
||||
val binder = Binder(source)
|
||||
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterClass::class.java)).get()
|
||||
assertThat(bean.stringDataValue).isEqualTo("test")
|
||||
}
|
||||
|
||||
|
@ -235,7 +243,9 @@ class KotlinConstructorParametersBinderTests {
|
|||
val stringValue: String = "my data",
|
||||
val enumValue: ExampleEnum = ExampleEnum.BAR_BAZ)
|
||||
|
||||
data class ExampleNamedParameterBean(@Name("stringValue") val stringDataValue: String)
|
||||
data class ExampleNamedParameterDataClass(@Name("stringValue") val stringDataValue: String)
|
||||
|
||||
class ExampleNamedParameterClass(@Name("stringValue") val stringDataValue: String)
|
||||
|
||||
data class GenericValue<T>(
|
||||
val value: T
|
||||
|
|
Loading…
Reference in New Issue