Skip to content

Commit

Permalink
Merge branch '3.2.x' into 3.3.x
Browse files Browse the repository at this point in the history
Closes gh-41589
  • Loading branch information
wilkinsona committed Jul 23, 2024
2 parents db4b483 + 72867a3 commit 72fd3f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,25 @@ void bindWhenBindingToPathTypeWithDefaultValue() { // gh-21263
}

@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();
Expand Down Expand Up @@ -886,11 +896,11 @@ Path getPath() {

}

static class NamedParameter {
static class NamedConstructorParameter {

private final String importName;

NamedParameter(@Name("import") String importName) {
NamedConstructorParameter(@Name("import") String importName) {
this.importName = importName;
}

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

}

record NamedRecordComponent(@Name("import") String importName) {
}

static class NonExtractableParameterName {

private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72fd3f9

Please sign in to comment.