use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldBindHierarchy.
@Test
void bindToClassShouldBindHierarchy() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "123");
source.put("foo.long-value", "456");
this.sources.add(source);
ExampleSubclassBean bean = this.binder.bind("foo", Bindable.of(ExampleSubclassBean.class)).get();
assertThat(bean.getIntValue()).isEqualTo(123);
assertThat(bean.getLongValue()).isEqualTo(456);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWithNoConverterForValue.
@Test
void bindToMapWithNoConverterForValue() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "a,b");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", STRING_STRING_MAP));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class BinderTests method bindToJavaBeanWhenNonIterableShouldReturnPopulatedBean.
@Test
void bindToJavaBeanWhenNonIterableShouldReturnPopulatedBean() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource("foo.value", "bar");
this.sources.add(source.nonIterable());
JavaBean result = this.binder.bind("foo", Bindable.of(JavaBean.class)).get();
assertThat(result.getValue()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class BinderTests method bindOrCreateWhenBindSuccessfulShouldReturnBoundValue.
@Test
void bindOrCreateWhenBindSuccessfulShouldReturnBoundValue() {
this.sources.add(new MockConfigurationPropertySource("foo.value", "bar"));
JavaBean result = this.binder.bindOrCreate("foo", Bindable.of(JavaBean.class));
assertThat(result.getValue()).isEqualTo("bar");
assertThat(result.getItems()).isEmpty();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class BinderTests method bindToValueWithCustomPropertyEditorShouldReturnConvertedValue.
@Test
void bindToValueWithCustomPropertyEditorShouldReturnConvertedValue() {
this.binder = new Binder(this.sources, null, null, (registry) -> registry.registerCustomEditor(JavaBean.class, new JavaBeanPropertyEditor()));
this.sources.add(new MockConfigurationPropertySource("foo", "123"));
BindResult<JavaBean> result = this.binder.bind("foo", Bindable.of(JavaBean.class));
assertThat(result.get().getValue()).isEqualTo("123");
}
Aggregations