use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassWhenNoDefaultConstructorShouldBind.
@Test
void bindToClassWhenNoDefaultConstructorShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "bar");
this.sources.add(source);
BindResult<ExampleWithNonDefaultConstructor> bean = this.binder.bind("foo", Bindable.of(ExampleWithNonDefaultConstructor.class));
assertThat(bean.isBound()).isTrue();
ExampleWithNonDefaultConstructor boundBean = bean.get();
assertThat(boundBean.getValue()).isEqualTo("bar");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindWhenValueIsConvertedWithPropertyEditorShouldBind.
@Test
void bindWhenValueIsConvertedWithPropertyEditorShouldBind() {
// gh-12166
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "java.lang.RuntimeException");
this.sources.add(source);
ExampleWithPropertyEditorType bean = this.binder.bind("foo", Bindable.of(ExampleWithPropertyEditorType.class)).get();
assertThat(bean.getValue()).isEqualTo(RuntimeException.class);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindWhenHasPackagePrivateSetterShouldBind.
@Test
void bindWhenHasPackagePrivateSetterShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.property", "test");
this.sources.add(source);
PackagePrivateSetterBean bean = this.binder.bind("foo", Bindable.of(PackagePrivateSetterBean.class)).get();
assertThat(bean.getProperty()).isEqualTo("test");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldBindToMap.
@Test
void bindToClassShouldBindToMap() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.map.foo-bar", "1");
source.put("foo.map.bar-baz", "2");
this.sources.add(source);
ExampleMapBean bean = this.binder.bind("foo", Bindable.of(ExampleMapBean.class)).get();
assertThat(bean.getMap()).containsExactly(entry(ExampleEnum.FOO_BAR, 1), entry(ExampleEnum.BAR_BAZ, 2));
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToClassShouldBindToSet.
@Test
void bindToClassShouldBindToSet() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.set[0]", "foo-bar");
source.put("foo.set[1]", "bar-baz");
this.sources.add(source);
ExampleSetBean bean = this.binder.bind("foo", Bindable.of(ExampleSetBean.class)).get();
assertThat(bean.getSet()).containsExactly(ExampleEnum.FOO_BAR, ExampleEnum.BAR_BAZ);
}
Aggregations