Search in sources :

Example 61 with MockConfigurationPropertySource

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

the class BinderTests method bindToJavaBeanShouldReturnPopulatedBean.

@Test
void bindToJavaBeanShouldReturnPopulatedBean() {
    this.sources.add(new MockConfigurationPropertySource("foo.value", "bar"));
    JavaBean result = this.binder.bind("foo", Bindable.of(JavaBean.class)).get();
    assertThat(result.getValue()).isEqualTo("bar");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 62 with MockConfigurationPropertySource

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

the class BinderTests method bindToJavaBeanWhenHasPropertyWithSameNameShouldStillBind.

@Test
void bindToJavaBeanWhenHasPropertyWithSameNameShouldStillBind() {
    // gh-10945
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo", "boom");
    source.put("foo.value", "bar");
    this.sources.add(source);
    JavaBean result = this.binder.bind("foo", Bindable.of(JavaBean.class)).get();
    assertThat(result.getValue()).isEqualTo("bar");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 63 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionShouldReturnPopulatedCollection.

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

Example 64 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionWhenCommaListWithPlaceholdersShouldReturnPopulatedCollection.

@Test
void bindToCollectionWhenCommaListWithPlaceholdersShouldReturnPopulatedCollection() {
    StandardEnvironment environment = new StandardEnvironment();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "bar=1,2,3");
    this.binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment));
    this.sources.add(new MockConfigurationPropertySource("foo", "${bar}"));
    List<Integer> result = this.binder.bind("foo", INTEGER_LIST).get();
    assertThat(result).containsExactly(1, 2, 3);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 65 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionWhenItemContainsCommasShouldReturnPopulatedCollection.

@Test
void bindToCollectionWhenItemContainsCommasShouldReturnPopulatedCollection() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo[0]", "1,2");
    source.put("foo[1]", "3");
    this.sources.add(source);
    List<String> result = this.binder.bind("foo", STRING_LIST).get();
    assertThat(result).containsExactly("1,2", "3");
}
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