use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldBindToCollectionWithDelimiter.
@Test
void bindToClassShouldBindToCollectionWithDelimiter() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.collection", "foo-bar|bar-baz");
this.sources.add(source);
ExampleCollectionBeanWithDelimiter bean = this.binder.bind("foo", Bindable.of(ExampleCollectionBeanWithDelimiter.class)).get();
assertThat(bean.getCollection()).containsExactly(ExampleEnum.FOO_BAR, ExampleEnum.BAR_BAZ);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWithOverriddenPropertyShouldSetSubclassProperty.
@Test
void bindToClassWithOverriddenPropertyShouldSetSubclassProperty() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value-bean.int-value", "123");
source.put("foo.value-bean.sub-int-value", "456");
this.sources.add(source);
ExampleNestedSubclassBean bean = this.binder.bind("foo", Bindable.of(ExampleNestedSubclassBean.class)).get();
assertThat(bean.getValueBean()).isNotNull();
assertThat(bean.getValueBean().getIntValue()).isEqualTo(123);
assertThat(bean.getValueBean().getSubIntValue()).isEqualTo(456);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldBindNested.
@Test
void bindToClassShouldBindNested() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value-bean.int-value", "123");
source.put("foo.value-bean.string-value", "foo");
this.sources.add(source);
ExampleNestedBean bean = this.binder.bind("foo", Bindable.of(ExampleNestedBean.class)).get();
assertThat(bean.getValueBean().getIntValue()).isEqualTo(123);
assertThat(bean.getValueBean().getStringValue()).isEqualTo("foo");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldIgnoreInvalidAccessors.
@Test
void bindToClassShouldIgnoreInvalidAccessors() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.name", "something");
this.sources.add(source);
ExampleWithInvalidAccessors bean = this.binder.bind("foo", Bindable.of(ExampleWithInvalidAccessors.class)).get();
assertThat(bean.getName()).isEqualTo("something");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWhenHasNoSetterShouldBindToMap.
@Test
void bindToClassWhenHasNoSetterShouldBindToMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.map.foo-bar", "1");
source.put("foo.map.bar-baz", "2");
this.sources.add(source);
ExampleMapBeanWithoutSetter bean = this.binder.bind("foo", Bindable.of(ExampleMapBeanWithoutSetter.class)).get();
assertThat(bean.getMap()).containsExactly(entry(ExampleEnum.FOO_BAR, 1), entry(ExampleEnum.BAR_BAZ, 2));
}
Aggregations