Search in sources :

Example 76 with MockConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.

the class ArrayBinderTests method bindToArrayShouldReturnArray.

@Test
void bindToArrayShouldReturnArray() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo[0]", "1");
    source.put("foo[1]", "2");
    source.put("foo[2]", "3");
    this.sources.add(source);
    Integer[] result = this.binder.bind("foo", INTEGER_ARRAY).get();
    assertThat(result).containsExactly(1, 2, 3);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 77 with MockConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.

the class ArrayBinderTests method bindToArrayWhenEmptyStringShouldReturnEmptyArray.

@Test
void bindToArrayWhenEmptyStringShouldReturnEmptyArray() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo", "");
    this.sources.add(source);
    String[] result = this.binder.bind("foo", Bindable.of(String[].class)).get();
    assertThat(result).isNotNull().isEmpty();
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 78 with MockConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.

the class ArrayBinderTests method bindToArrayWhenNestedListShouldReturnPopulatedArray.

@Test
void bindToArrayWhenNestedListShouldReturnPopulatedArray() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo[0][0]", "1");
    source.put("foo[0][1]", "2");
    source.put("foo[1][0]", "3");
    source.put("foo[1][1]", "4");
    this.sources.add(source);
    ResolvableType type = ResolvableType.forArrayComponent(INTEGER_LIST.getType());
    Bindable<List<Integer>[]> target = Bindable.of(type);
    List<Integer>[] result = this.binder.bind("foo", target).get();
    assertThat(result).hasSize(2);
    assertThat(result[0]).containsExactly(1, 2);
    assertThat(result[1]).containsExactly(3, 4);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ArrayList(java.util.ArrayList) List(java.util.List) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 79 with MockConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.

the class ArrayBinderTests method bindToArrayWhenCommaListShouldReturnPopulatedArray.

@Test
void bindToArrayWhenCommaListShouldReturnPopulatedArray() {
    this.sources.add(new MockConfigurationPropertySource("foo", "1,2,3"));
    int[] result = this.binder.bind("foo", Bindable.of(int[].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 80 with MockConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MockConfigurationPropertySource in project spring-boot by spring-projects.

the class ArrayBinderTests method bindToArrayWhenIndexedAndCommaListShouldOnlyUseFirst.

@Test
void bindToArrayWhenIndexedAndCommaListShouldOnlyUseFirst() {
    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");
    int[] result = this.binder.bind("foo", Bindable.of(int[].class)).get();
    assertThat(result).containsExactly(1, 2);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) 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