use of org.springframework.boot.context.properties.bind.BinderTests.JavaBean in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapNonScalarCollectionShouldPopulateMap.
@Test
void bindToMapNonScalarCollectionShouldPopulateMap() {
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType());
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar[0].value", "a");
source.put("foo.bar[1].value", "b");
source.put("foo.bar[2].value", "c");
this.sources.add(source);
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar").stream().map(JavaBean::getValue).collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.bind.BinderTests.JavaBean in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapNonScalarCollectionWithDotKeysShouldBind.
@Test
void bindToMapNonScalarCollectionWithDotKeysShouldBind() {
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz[0].value", "a");
mockSource.put("foo.bar.baz[1].value", "b");
mockSource.put("foo.bar.baz[2].value", "c");
this.sources.add(mockSource);
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue).collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.bind.BinderTests.JavaBean in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToNonScalarCollectionShouldReturnPopulatedCollection.
@Test
void bindToNonScalarCollectionShouldReturnPopulatedCollection() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0].value", "a");
source.put("foo[1].value", "b");
source.put("foo[2].value", "c");
this.sources.add(source);
Bindable<List<JavaBean>> target = Bindable.listOf(JavaBean.class);
List<JavaBean> result = this.binder.bind("foo", target).get();
assertThat(result).hasSize(3);
List<String> values = result.stream().map(JavaBean::getValue).collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c");
}
Aggregations