Merge branch '3.3.x'

Closes gh-41590
This commit is contained in:
Andy Wilkinson 2024-07-23 10:06:46 +01:00
commit c790deb7d2
2 changed files with 31 additions and 8 deletions

View File

@ -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;

View File

@ -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