use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWithMultipleConstructorsAndFilterShouldBind.
@Test
void bindToClassWithMultipleConstructorsAndFilterShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
this.sources.add(source);
Constructor<?>[] constructors = MultipleConstructorsBean.class.getDeclaredConstructors();
Constructor<?> constructor = (constructors[0].getParameterCount() == 1) ? constructors[0] : constructors[1];
Binder binder = new Binder(this.sources, null, (ConversionService) null, null, null, (bindable, isNestedConstructorBinding) -> constructor);
MultipleConstructorsBean bound = binder.bind("foo", Bindable.of(MultipleConstructorsBean.class)).get();
assertThat(bound.getIntValue()).isEqualTo(12);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindWithAnnotationsAndDefaultValue.
@Test
void bindWithAnnotationsAndDefaultValue() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar", "hello");
this.sources.add(source);
ConverterAnnotatedExampleBean bean = this.binder.bind("foo", Bindable.of(ConverterAnnotatedExampleBean.class)).get();
assertThat(bean.getDate().toString()).isEqualTo("2019-05-10");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToAnnotationNamedParameter.
@Test
void bindToAnnotationNamedParameter() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("test.import", "test");
this.sources.add(source);
Bindable<NamedParameter> target = Bindable.of(NamedParameter.class);
NamedParameter bound = this.binder.bindOrCreate("test", target);
assertThat(bound.getImportName()).isEqualTo("test");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWhenHasPackagePrivateConstructorShouldBind.
@Test
void bindToClassWhenHasPackagePrivateConstructorShouldBind() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.property", "test");
this.sources.add(source);
ExamplePackagePrivateConstructorBean bound = this.binder.bind("foo", Bindable.of(ExamplePackagePrivateConstructorBean.class)).get();
assertThat(bound.getProperty()).isEqualTo("test");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ValueObjectBinderTests method bindToClassWhenNoParameterBoundShouldReturnNull.
@Test
void bindToClassWhenNoParameterBoundShouldReturnNull() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
this.sources.add(source.nonIterable());
BindResult<ExampleFailingConstructorBean> result = this.binder.bind("foo", Bindable.of(ExampleFailingConstructorBean.class));
assertThat(result.isBound()).isFalse();
}
Aggregations