Merge branch '2.0.x'
This commit is contained in:
commit
e524adb2fc
|
@ -128,9 +128,10 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
|
||||||
}
|
}
|
||||||
for (ConfigurationPropertyName name : (IterableConfigurationPropertySource) source
|
for (ConfigurationPropertyName name : (IterableConfigurationPropertySource) source
|
||||||
.filter(root::isAncestorOf)) {
|
.filter(root::isAncestorOf)) {
|
||||||
name = name.chop(root.getNumberOfElements() + 1);
|
ConfigurationPropertyName choppedName = name
|
||||||
if (name.isLastElementIndexed()) {
|
.chop(root.getNumberOfElements() + 1);
|
||||||
String key = name.getLastElement(Form.UNIFORM);
|
if (choppedName.isLastElementIndexed()) {
|
||||||
|
String key = choppedName.getLastElement(Form.UNIFORM);
|
||||||
ConfigurationProperty value = source.getConfigurationProperty(name);
|
ConfigurationProperty value = source.getConfigurationProperty(name);
|
||||||
children.add(key, value);
|
children.add(key, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,29 @@ public class CollectionBinderTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bindToNonScalarCollectionWhenNonSequentialShouldThrowException() {
|
||||||
|
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||||
|
source.put("foo[0].value", "1");
|
||||||
|
source.put("foo[1].value", "2");
|
||||||
|
source.put("foo[4].value", "4");
|
||||||
|
this.sources.add(source);
|
||||||
|
try {
|
||||||
|
Bindable<List<JavaBean>> target = Bindable.listOf(JavaBean.class);
|
||||||
|
this.binder.bind("foo", target);
|
||||||
|
fail("No exception thrown");
|
||||||
|
}
|
||||||
|
catch (BindException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex
|
||||||
|
.getCause()).getUnboundProperties();
|
||||||
|
assertThat(unbound).hasSize(1);
|
||||||
|
ConfigurationProperty property = unbound.iterator().next();
|
||||||
|
assertThat(property.getName().toString()).isEqualTo("foo[4].value");
|
||||||
|
assertThat(property.getValue()).isEqualTo("4");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindToCollectionWhenNonIterableShouldReturnPopulatedCollection() {
|
public void bindToCollectionWhenNonIterableShouldReturnPopulatedCollection() {
|
||||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||||
|
|
Loading…
Reference in New Issue