use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWhenHasNoPrefixShouldCreateBoundBean.
@Test
void bindToClassWhenHasNoPrefixShouldCreateBoundBean() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("int-value", "12");
source.put("long-value", "34");
source.put("boolean-value", "true");
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.isBooleanValue()).isTrue();
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 ValueObjectBinderTests method bindToClassWithMultipleConstructorsShouldNotBind.
@Test
void bindToClassWithMultipleConstructorsShouldNotBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
boolean bound = this.binder.bind("foo", Bindable.of(MultipleConstructorsBean.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 bindToClassWithNoValueForPrimitiveShouldUseDefault.
@Test
void bindToClassWithNoValueForPrimitiveShouldUseDefault() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.string-value", "foo");
this.sources.add(source);
ExampleValueBean bean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class)).get();
assertThat(bean.getIntValue()).isEqualTo(0);
assertThat(bean.getLongValue()).isEqualTo(0);
assertThat(bean.isBooleanValue()).isEqualTo(false);
assertThat(bean.getStringValue()).isEqualTo("foo");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindWhenAllPropertiesBoundShouldClearConfigurationProperty.
@Test
void bindWhenAllPropertiesBoundShouldClearConfigurationProperty() {
// gh-18704
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "hello");
this.sources.add(source);
Bindable<ValidatingConstructorBean> target = Bindable.of(ValidatingConstructorBean.class);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", target)).satisfies(this::noConfigurationProperty);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindWhenBindingToPathTypeWithValue.
@Test
void bindWhenBindingToPathTypeWithValue() {
// gh-21263
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.name", "test");
source.put("test.path", "specific_value");
this.sources.add(source);
Bindable<PathBean> target = Bindable.of(PathBean.class);
PathBean bound = this.binder.bind("test", target).get();
assertThat(bound.getName()).isEqualTo("test");
assertThat(bound.getPath()).isEqualTo(Paths.get("specific_value"));
}
Aggregations