use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToBeanWithExceptionInGetterForExistingValue.
@Test
void bindToBeanWithExceptionInGetterForExistingValue() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.values", "a,b,c");
this.sources.add(source);
BeanWithGetterException result = this.binder.bind("foo", Bindable.of(BeanWithGetterException.class)).get();
assertThat(result.getValues()).containsExactly("a", "b", "c");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToCollectionWhenIndexedAndCommaListShouldOnlyUseFirst.
@Test
void bindToCollectionWhenIndexedAndCommaListShouldOnlyUseFirst() {
MockConfigurationPropertySource source1 = new MockConfigurationPropertySource();
source1.put("foo[0]", "1");
source1.put("foo[1]", "2");
this.sources.add(source1);
MockConfigurationPropertySource source2 = new MockConfigurationPropertySource();
source2.put("foo", "2,3");
List<Integer> result = this.binder.bind("foo", INTEGER_LIST).get();
assertThat(result).containsExactly(1, 2);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToCollectionWhenNonSequentialShouldThrowException.
@Test
void bindToCollectionWhenNonSequentialShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "2");
source.put("foo[1]", "1");
source.put("foo[3]", "3");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", INTEGER_LIST)).satisfies((ex) -> {
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex.getCause()).getUnboundProperties();
assertThat(unbound).hasSize(1);
ConfigurationProperty property = unbound.iterator().next();
assertThat(property.getName().toString()).isEqualTo("foo[3]");
assertThat(property.getValue()).isEqualTo("3");
});
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class JavaBeanBinderTests method bindToInstanceShouldBindToInstance.
@Test
void bindToInstanceShouldBindToInstance() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.int-value", "12");
source.put("foo.long-value", "34");
source.put("foo.string-value", "foo");
source.put("foo.enum-value", "foo-bar");
this.sources.add(source);
ExampleValueBean bean = new ExampleValueBean();
ExampleValueBean boundBean = this.binder.bind("foo", Bindable.of(ExampleValueBean.class).withExistingValue(bean)).get();
assertThat(boundBean).isSameAs(bean);
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 bindToClassWithOverloadedSetterShouldUseSetterThatMatchesField.
@Test
void bindToClassWithOverloadedSetterShouldUseSetterThatMatchesField() {
// gh-16206
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.property", "some string");
this.sources.add(source);
PropertyWithOverloadedSetter bean = this.binder.bind("foo", Bindable.of(PropertyWithOverloadedSetter.class)).get();
assertThat(bean.getProperty()).isEqualTo("some string");
}
Aggregations