|
|
@ -131,6 +131,42 @@ class NoUnboundElementsBindHandlerTests {
|
|
|
|
.contains("The elements [example.foo[0]] were left unbound"));
|
|
|
|
.contains("The elements [example.foo[0]] were left unbound"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundNestedCollectionProperties() {
|
|
|
|
|
|
|
|
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
|
|
|
|
|
|
|
|
source1.put("example.nested[0].string-value", "bar");
|
|
|
|
|
|
|
|
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
|
|
|
|
|
|
|
|
source2.put("example.nested[0].string-value", "bar");
|
|
|
|
|
|
|
|
source2.put("example.nested[0].int-value", "2");
|
|
|
|
|
|
|
|
source2.put("example.nested[1].string-value", "baz");
|
|
|
|
|
|
|
|
source2.put("example.nested[1].other-nested.baz", "baz");
|
|
|
|
|
|
|
|
this.sources.add(source1);
|
|
|
|
|
|
|
|
this.sources.add(source2);
|
|
|
|
|
|
|
|
this.binder = new Binder(this.sources);
|
|
|
|
|
|
|
|
NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler();
|
|
|
|
|
|
|
|
ExampleWithNestedList bound = this.binder.bind("example", Bindable.of(ExampleWithNestedList.class), handler)
|
|
|
|
|
|
|
|
.get();
|
|
|
|
|
|
|
|
assertThat(bound.getNested().get(0).getStringValue()).isEqualTo("bar");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void bindWhenUsingNoUnboundElementsHandlerAndUnboundCollectionElementsWithInvalidPropertyShouldThrowException() {
|
|
|
|
|
|
|
|
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
|
|
|
|
|
|
|
|
source1.put("example.nested[0].string-value", "bar");
|
|
|
|
|
|
|
|
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
|
|
|
|
|
|
|
|
source2.put("example.nested[0].string-value", "bar");
|
|
|
|
|
|
|
|
source2.put("example.nested[1].int-value", "1");
|
|
|
|
|
|
|
|
source2.put("example.nested[1].invalid", "baz");
|
|
|
|
|
|
|
|
this.sources.add(source1);
|
|
|
|
|
|
|
|
this.sources.add(source2);
|
|
|
|
|
|
|
|
this.binder = new Binder(this.sources);
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BindException.class)
|
|
|
|
|
|
|
|
.isThrownBy(() -> this.binder.bind("example", Bindable.of(ExampleWithNestedList.class),
|
|
|
|
|
|
|
|
new NoUnboundElementsBindHandler()))
|
|
|
|
|
|
|
|
.satisfies((ex) -> assertThat(ex.getCause().getMessage())
|
|
|
|
|
|
|
|
.contains("The elements [example.nested[1].invalid] were left unbound"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class Example {
|
|
|
|
static class Example {
|
|
|
|
|
|
|
|
|
|
|
|
private String foo;
|
|
|
|
private String foo;
|
|
|
@ -159,4 +195,66 @@ class NoUnboundElementsBindHandlerTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class ExampleWithNestedList {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Nested> nested;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Nested> getNested() {
|
|
|
|
|
|
|
|
return this.nested;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setNested(List<Nested> nested) {
|
|
|
|
|
|
|
|
this.nested = nested;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class Nested {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String stringValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Integer intValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private OtherNested otherNested;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getStringValue() {
|
|
|
|
|
|
|
|
return this.stringValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setStringValue(String value) {
|
|
|
|
|
|
|
|
this.stringValue = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer getIntValue() {
|
|
|
|
|
|
|
|
return this.intValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setIntValue(Integer intValue) {
|
|
|
|
|
|
|
|
this.intValue = intValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OtherNested getOtherNested() {
|
|
|
|
|
|
|
|
return this.otherNested;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setOtherNested(OtherNested otherNested) {
|
|
|
|
|
|
|
|
this.otherNested = otherNested;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class OtherNested {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String baz;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getBaz() {
|
|
|
|
|
|
|
|
return this.baz;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setBaz(String baz) {
|
|
|
|
|
|
|
|
this.baz = baz;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|