use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayShouldReturnArray.
@Test
void bindToArrayShouldReturnArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "1");
source.put("foo[1]", "2");
source.put("foo[2]", "3");
this.sources.add(source);
Integer[] result = this.binder.bind("foo", INTEGER_ARRAY).get();
assertThat(result).containsExactly(1, 2, 3);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenEmptyStringShouldReturnEmptyArray.
@Test
void bindToArrayWhenEmptyStringShouldReturnEmptyArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "");
this.sources.add(source);
String[] result = this.binder.bind("foo", Bindable.of(String[].class)).get();
assertThat(result).isNotNull().isEmpty();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenNestedListShouldReturnPopulatedArray.
@Test
void bindToArrayWhenNestedListShouldReturnPopulatedArray() {
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.forArrayComponent(INTEGER_LIST.getType());
Bindable<List<Integer>[]> target = Bindable.of(type);
List<Integer>[] result = this.binder.bind("foo", target).get();
assertThat(result).hasSize(2);
assertThat(result[0]).containsExactly(1, 2);
assertThat(result[1]).containsExactly(3, 4);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenCommaListShouldReturnPopulatedArray.
@Test
void bindToArrayWhenCommaListShouldReturnPopulatedArray() {
this.sources.add(new MockConfigurationPropertySource("foo", "1,2,3"));
int[] result = this.binder.bind("foo", Bindable.of(int[].class)).get();
assertThat(result).containsExactly(1, 2, 3);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
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);
}
Aggregations