Search in sources :

Example 81 with MockConfigurationPropertySource

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());
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 82 with MockConfigurationPropertySource

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);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 83 with MockConfigurationPropertySource

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");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 84 with MockConfigurationPropertySource

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();
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 85 with MockConfigurationPropertySource

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));
}
Also used : InOrder(org.mockito.InOrder) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)207 Test (org.junit.jupiter.api.Test)204 Map (java.util.Map)18 HashMap (java.util.HashMap)17 LinkedHashMap (java.util.LinkedHashMap)17 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Binder (org.springframework.boot.context.properties.bind.Binder)15 InOrder (org.mockito.InOrder)8 LinkedList (java.util.LinkedList)7 ResolvableType (org.springframework.core.ResolvableType)7 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)5 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)5 StandardEnvironment (org.springframework.core.env.StandardEnvironment)5 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)4 LocalDate (java.time.LocalDate)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 BindException (org.springframework.boot.context.properties.bind.BindException)3