use of cn.taketoday.context.properties.source.MockConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenNestedShouldReturnPopulatedArray.
@Test
void bindToArrayWhenNestedShouldReturnPopulatedArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0][0]", "1");
source.put("foo[0][1]", "2");
source.put("foo[1][0]", "3");
source.put("foo[1][1]", "4");
this.sources.add(source);
ResolvableType type = ResolvableType.fromArrayComponent(INTEGER_ARRAY.getType());
Bindable<Integer[][]> target = Bindable.of(type);
Integer[][] result = this.binder.bind("foo", target).get();
assertThat(result).hasDimensions(2, 2);
assertThat(result[0]).containsExactly(1, 2);
assertThat(result[1]).containsExactly(3, 4);
}
use of cn.taketoday.context.properties.source.MockConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenNonIterableShouldReturnPopulatedArray.
@Test
void bindToArrayWhenNonIterableShouldReturnPopulatedArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[1]", "2");
source.put("foo[0]", "1");
source.put("foo[2]", "3");
this.sources.add(source.nonIterable());
Integer[] result = this.binder.bind("foo", INTEGER_ARRAY).get();
assertThat(result).containsExactly(1, 2, 3);
}
use of cn.taketoday.context.properties.source.MockConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenIndexedAndCommaListShouldOnlyUseFirst.
@Test
void bindToArrayWhenIndexedAndCommaListShouldOnlyUseFirst() {
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
source1.put("foo[0]", "1");
source1.put("foo[1]", "2");
this.sources.add(source1);
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
source2.put("foo", "2,3");
int[] result = this.binder.bind("foo", Bindable.of(int[].class)).get();
assertThat(result).containsExactly(1, 2);
}
use of cn.taketoday.context.properties.source.MockConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenMultipleSourceShouldOnlyUseFirst.
@Test
void bindToArrayWhenMultipleSourceShouldOnlyUseFirst() {
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
source1.put("bar", "baz");
this.sources.add(source1);
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
source2.put("foo[0]", "1");
source2.put("foo[1]", "2");
this.sources.add(source2);
MockConfigurationPropertySource source3 = new MockConfigurationPropertySource();
source3.put("foo[0]", "7");
source3.put("foo[1]", "8");
source3.put("foo[2]", "9");
this.sources.add(source3);
Integer[] result = this.binder.bind("foo", INTEGER_ARRAY).get();
assertThat(result).containsExactly(1, 2);
}
use of cn.taketoday.context.properties.source.MockConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenNonSequentialShouldThrowException.
@Test
void bindToArrayWhenNonSequentialShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "2");
source.put("foo[1]", "1");
source.put("foo[3]", "3");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", INTEGER_ARRAY)).satisfies((ex) -> {
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex.getCause()).getUnboundProperties();
assertThat(unbound.size()).isEqualTo(1);
ConfigurationProperty property = unbound.iterator().next();
assertThat(property.getName().toString()).isEqualTo("foo[3]");
assertThat(property.getValue()).isEqualTo("3");
});
}
Aggregations