use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldReturnPopulatedMap.
@Test
void bindToMapShouldReturnPopulatedMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "1");
source.put("foo.[baz]", "2");
source.put("foo[BiNg]", "3");
this.sources.add(source);
Map<String, String> result = this.binder.bind("foo", STRING_STRING_MAP).get();
assertThat(result).hasSize(3);
assertThat(result).containsEntry("bar", "1");
assertThat(result).containsEntry("baz", "2");
assertThat(result).containsEntry("BiNg", "3");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWhenEmptyRootNameShouldBindMap.
@Test
void bindToMapWhenEmptyRootNameShouldBindMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("bar.baz", "1");
source.put("bar.bin", "2");
this.sources.add(source);
Map<String, Integer> result = this.binder.bind("", STRING_INTEGER_MAP).get();
assertThat(result).hasSize(2);
assertThat(result).containsEntry("bar.baz", 1).containsEntry("bar.bin", 2);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldConvertMapValue.
@Test
void bindToMapShouldConvertMapValue() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "1");
source.put("foo.[baz]", "2");
source.put("foo[BiNg]", "3");
source.put("faf.bar", "x");
this.sources.add(source);
Map<String, Integer> result = this.binder.bind("foo", STRING_INTEGER_MAP).get();
assertThat(result).hasSize(3);
assertThat(result).containsEntry("bar", 1);
assertThat(result).containsEntry("baz", 2);
assertThat(result).containsEntry("BiNg", 3);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapShouldRespectMapType.
@Test
void bindToMapShouldRespectMapType() {
this.sources.add(new MockConfigurationPropertySource("foo.bar", "1"));
ResolvableType type = ResolvableType.forClassWithGenerics(HashMap.class, String.class, Integer.class);
Object defaultMap = this.binder.bind("foo", STRING_INTEGER_MAP).get();
Object customMap = this.binder.bind("foo", Bindable.of(type)).get();
assertThat(customMap).isExactlyInstanceOf(HashMap.class).isNotInstanceOf(defaultMap.getClass());
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToInstanceWithExistingValueShouldReturnUnbound.
@Test
void bindToInstanceWithExistingValueShouldReturnUnbound() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
this.sources.add(source);
ExampleNestedBean existingValue = new ExampleNestedBean();
ExampleValueBean valueBean = new ExampleValueBean();
existingValue.setValueBean(valueBean);
BindResult<ExampleNestedBean> result = this.binder.bind("foo", Bindable.of(ExampleNestedBean.class).withExistingValue(existingValue));
assertThat(result.isBound()).isFalse();
}
Aggregations