use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayShouldBindCharArray.
@Test
void bindToArrayShouldBindCharArray() {
this.sources.add(new MockConfigurationPropertySource("foo", "word"));
char[] result = this.binder.bind("foo", Bindable.of(char[].class)).get();
assertThat(result).containsExactly("word".toCharArray());
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayShouldUsePropertyEditor.
@Test
void bindToArrayShouldUsePropertyEditor() {
// gh-12166
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "java.lang.RuntimeException");
source.put("foo[1]", "java.lang.IllegalStateException");
this.sources.add(source);
assertThat(this.binder.bind("foo", Bindable.of(Class[].class)).get()).containsExactly(RuntimeException.class, IllegalStateException.class);
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenHasSpacesShouldTrim.
@Test
void bindToArrayWhenHasSpacesShouldTrim() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "1, 2,3");
this.sources.add(source);
String[] result = this.binder.bind("foo", Bindable.of(String[].class)).get();
assertThat(result).containsExactly("1", "2", "3");
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToArrayWhenNoValueShouldReturnUnbound.
@Test
void bindToArrayWhenNoValueShouldReturnUnbound() {
this.sources.add(new MockConfigurationPropertySource("faf.bar", "1"));
BindResult<Integer[]> result = this.binder.bind("foo", INTEGER_ARRAY);
assertThat(result.isBound()).isFalse();
}
use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.
the class ArrayBinderTests method bindToCollectionShouldTriggerOnSuccess.
@Test
void bindToCollectionShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1"));
BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
this.binder.bind("foo", INTEGER_LIST, handler);
InOrder inOrder = inOrder(handler);
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo[0]")), eq(Bindable.of(Integer.class)), any(), eq(1));
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), eq(INTEGER_LIST), any(), isA(List.class));
}
Aggregations