use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWhenPropertiesMissingShouldReturnUnbound.
@Test
void bindToClassWhenPropertiesMissingShouldReturnUnbound() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("faf.int-value", "12");
this.sources.add(source);
BindResult<ExampleValueBean> bean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class));
assertThat(bean.isBound()).isFalse();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWhenHasNoPrefixShouldCreateBoundBean.
@Test
void bindToClassWhenHasNoPrefixShouldCreateBoundBean() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("int-value", "12");
source.put("long-value", "34");
source.put("string-value", "foo");
source.put("enum-value", "foo-bar");
this.sources.add(source);
ExampleValueBean bean = this.binder.bind(ConfigurationPropertyName.of(""), Bindable.of(ExampleValueBean.class)).get();
assertThat(bean.getIntValue()).isEqualTo(12);
assertThat(bean.getLongValue()).isEqualTo(34);
assertThat(bean.getStringValue()).isEqualTo("foo");
assertThat(bean.getEnumValue()).isEqualTo(ExampleEnum.FOO_BAR);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToInstanceWithNoPropertiesShouldReturnUnbound.
@Test
void bindToInstanceWithNoPropertiesShouldReturnUnbound() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
this.sources.add(source);
ExampleDefaultsBean bean = new ExampleDefaultsBean();
BindResult<ExampleDefaultsBean> boundBean = this.binder.bind("foo", Bindable.of(ExampleDefaultsBean.class).withExistingValue(bean));
assertThat(boundBean.isBound()).isFalse();
assertThat(bean.getFoo()).isEqualTo(123);
assertThat(bean.getBar()).isEqualTo(456);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToExistingInstanceShouldLeaveDefaults.
@Test
void bindToExistingInstanceShouldLeaveDefaults() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "999");
this.sources.add(source);
ExampleDefaultsBean bean = new ExampleDefaultsBean();
bean.setFoo(888);
ExampleDefaultsBean boundBean = this.binder.bind("foo", Bindable.of(ExampleDefaultsBean.class).withExistingValue(bean)).get();
assertThat(boundBean).isSameAs(bean);
assertThat(bean.getFoo()).isEqualTo(888);
assertThat(bean.getBar()).isEqualTo(999);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWhenHasNoSetterAndImmutableShouldThrowException.
@Test
void bindToClassWhenHasNoSetterAndImmutableShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.nested.foo", "bar");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", Bindable.of(ExampleImmutableNestedBeanWithoutSetter.class)));
}
Aggregations