use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindWhenBindingToPathTypeWithDefaultValue.
@Test
void bindWhenBindingToPathTypeWithDefaultValue() {
// gh-21263
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.name", "test");
this.sources.add(source);
Bindable<PathBean> target = Bindable.of(PathBean.class);
PathBean bound = this.binder.bindOrCreate("test", target);
assertThat(bound.getName()).isEqualTo("test");
assertThat(bound.getPath()).isEqualTo(Paths.get("default_value"));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWithNoValueAndDefaultValueShouldNotBind.
@Test
void bindToClassWithNoValueAndDefaultValueShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.string-value", "foo");
this.sources.add(source);
assertThat(this.binder.bind("foo", Bindable.of(ExampleDefaultValueBean.class)).isBound()).isFalse();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWithOnlyDefaultConstructorShouldNotBind.
@Test
void bindToClassWithOnlyDefaultConstructorShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
boolean bound = this.binder.bind("foo", Bindable.of(DefaultConstructorBean.class)).isBound();
assertThat(bound).isFalse();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassShouldBindWithGenerics.
@Test
void bindToClassShouldBindWithGenerics() {
// gh-19156
ResolvableType type = ResolvableType.forClassWithGenerics(Map.class, String.class, String.class);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value.bar", "baz");
this.sources.add(source);
GenericValue<Map<String, String>> bean = this.binder.bind("foo", Bindable.<GenericValue<Map<String, String>>>of(ResolvableType.forClassWithGenerics(GenericValue.class, type))).get();
assertThat(bean.getValue().get("bar")).isEqualTo("baz");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource 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");
}
Aggregations