Skip to content

Commit 72fd3f9

Browse files
committed
Merge branch '3.2.x' into 3.3.x
Closes gh-41589
2 parents db4b483 + 72867a3 commit 72fd3f9

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ValueObjectBinderTests.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,25 @@ void bindWhenBindingToPathTypeWithDefaultValue() { // gh-21263
369369
}
370370

371371
@Test
372-
void bindToAnnotationNamedParameter() {
372+
void bindToAnnotationNamedConstructorParameter() {
373373
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
374374
source.put("test.import", "test");
375375
this.sources.add(source);
376-
Bindable<NamedParameter> target = Bindable.of(NamedParameter.class);
377-
NamedParameter bound = this.binder.bindOrCreate("test", target);
376+
Bindable<NamedConstructorParameter> target = Bindable.of(NamedConstructorParameter.class);
377+
NamedConstructorParameter bound = this.binder.bindOrCreate("test", target);
378378
assertThat(bound.getImportName()).isEqualTo("test");
379379
}
380380

381+
@Test
382+
void bindToAnnotationNamedRecordComponent() {
383+
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
384+
source.put("test.import", "test");
385+
this.sources.add(source);
386+
Bindable<NamedRecordComponent> target = Bindable.of(NamedRecordComponent.class);
387+
NamedRecordComponent bound = this.binder.bindOrCreate("test", target);
388+
assertThat(bound.importName()).isEqualTo("test");
389+
}
390+
381391
@Test
382392
void bindToRecordWithDefaultValue() {
383393
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
@@ -886,11 +896,11 @@ Path getPath() {
886896

887897
}
888898

889-
static class NamedParameter {
899+
static class NamedConstructorParameter {
890900

891901
private final String importName;
892902

893-
NamedParameter(@Name("import") String importName) {
903+
NamedConstructorParameter(@Name("import") String importName) {
894904
this.importName = importName;
895905
}
896906

@@ -900,6 +910,9 @@ String getImportName() {
900910

901911
}
902912

913+
record NamedRecordComponent(@Name("import") String importName) {
914+
}
915+
903916
static class NonExtractableParameterName {
904917

905918
private String value;

spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/bind/KotlinConstructorParametersBinderTests.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,18 @@ class KotlinConstructorParametersBinderTests {
179179
}
180180

181181
@Test
182-
fun `Bind to named constructor parameter`() {
182+
fun `Bind to named data class constructor parameter`() {
183183
val source = MockConfigurationPropertySource("foo.string-value", "test")
184184
val binder = Binder(source)
185-
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterBean::class.java)).get()
185+
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterDataClass::class.java)).get()
186+
assertThat(bean.stringDataValue).isEqualTo("test")
187+
}
188+
189+
@Test
190+
fun `Bind to named class constructor parameter`() {
191+
val source = MockConfigurationPropertySource("foo.string-value", "test")
192+
val binder = Binder(source)
193+
val bean = binder.bind("foo", Bindable.of(ExampleNamedParameterClass::class.java)).get()
186194
assertThat(bean.stringDataValue).isEqualTo("test")
187195
}
188196

@@ -235,7 +243,9 @@ class KotlinConstructorParametersBinderTests {
235243
val stringValue: String = "my data",
236244
val enumValue: ExampleEnum = ExampleEnum.BAR_BAZ)
237245

238-
data class ExampleNamedParameterBean(@Name("stringValue") val stringDataValue: String)
246+
data class ExampleNamedParameterDataClass(@Name("stringValue") val stringDataValue: String)
247+
248+
class ExampleNamedParameterClass(@Name("stringValue") val stringDataValue: String)
239249

240250
data class GenericValue<T>(
241251
val value: T

0 commit comments

Comments
 (0)