use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToImmutableCollectionShouldReturnPopulatedCollection.
@Test
void bindToImmutableCollectionShouldReturnPopulatedCollection() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.values", "a,b,c");
this.sources.add(source);
Set<String> result = this.binder.bind("foo.values", STRING_SET.withExistingValue(Collections.emptySet())).get();
assertThat(result).hasSize(3);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToBeanWithClonedArray.
@Test
void bindToBeanWithClonedArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar[0]", "hello");
this.sources.add(source);
Bindable<ClonedArrayBean> target = Bindable.of(ClonedArrayBean.class);
ClonedArrayBean bean = this.binder.bind("foo", target).get();
assertThat(bean.getBar()).containsExactly("hello");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToCollectionWhenNestedShouldReturnPopulatedCollection.
@Test
void bindToCollectionWhenNestedShouldReturnPopulatedCollection() {
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);
Bindable<List<List<Integer>>> target = Bindable.of(ResolvableType.forClassWithGenerics(List.class, INTEGER_LIST.getType()));
List<List<Integer>> result = this.binder.bind("foo", target).get();
assertThat(result).hasSize(2);
assertThat(result.get(0)).containsExactly(1, 2);
assertThat(result.get(1)).containsExactly(3, 4);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToSetShouldNotAllowDuplicateValues.
@Test
void bindToSetShouldNotAllowDuplicateValues() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.items-set", "a,b,c,c");
this.sources.add(source);
ExampleCollectionBean result = this.binder.bind("foo", ExampleCollectionBean.class).get();
assertThat(result.getItemsSet()).hasSize(3);
assertThat(result.getItemsSet()).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToCollectionWhenCommaListShouldReturnPopulatedCollection.
@Test
void bindToCollectionWhenCommaListShouldReturnPopulatedCollection() {
this.sources.add(new MockConfigurationPropertySource("foo", "1,2,3"));
List<Integer> result = this.binder.bind("foo", INTEGER_LIST).get();
assertThat(result).containsExactly(1, 2, 3);
}
Aggregations