Search in sources :

Example 71 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToNestedCollectionWhenEmptyStringShouldReturnEmptyCollection.

@Test
void bindToNestedCollectionWhenEmptyStringShouldReturnEmptyCollection() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.value", "one");
    source.put("foo.foos", "");
    this.sources.add(source);
    Bindable<BeanWithNestedCollection> target = Bindable.of(BeanWithNestedCollection.class);
    BeanWithNestedCollection foo = this.binder.bind("foo", target).get();
    assertThat(foo.getValue()).isEqualTo("one");
    assertThat(foo.getFoos()).isEmpty();
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 72 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionWhenHasExistingCollectionButNoValueShouldReturnUnbound.

@Test
void bindToCollectionWhenHasExistingCollectionButNoValueShouldReturnUnbound() {
    this.sources.add(new MockConfigurationPropertySource("faf[0]", "1"));
    List<Integer> existing = new LinkedList<>();
    existing.add(1000);
    BindResult<List<Integer>> result = this.binder.bind("foo", INTEGER_LIST.withExistingValue(existing));
    assertThat(result.isBound()).isFalse();
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 73 with MockConfigurationPropertySource

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

the class BinderTests method bindToJavaBeanWhenHandlerOnStartReturnsNullShouldReturnUnbound.

@Test
void bindToJavaBeanWhenHandlerOnStartReturnsNullShouldReturnUnbound() {
    // gh-18129
    this.sources.add(new MockConfigurationPropertySource("foo.value", "bar"));
    BindResult<JavaBean> result = this.binder.bind("foo", Bindable.of(JavaBean.class), new BindHandler() {

        @Override
        public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) {
            return null;
        }
    });
    assertThat(result.isBound()).isFalse();
}
Also used : ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ValidationBindHandler(org.springframework.boot.context.properties.bind.validation.ValidationBindHandler) Test(org.junit.jupiter.api.Test)

Example 74 with MockConfigurationPropertySource

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

the class BinderTests method bindToBeanWithCycle.

@Test
void bindToBeanWithCycle() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    this.sources.add(source.nonIterable());
    Bindable<CycleBean1> target = Bindable.of(CycleBean1.class);
    this.binder.bind("foo", target);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 75 with MockConfigurationPropertySource

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

the class BinderTests method bindToJavaBeanWithPublicConstructor.

private JavaBeanWithPublicConstructor bindToJavaBeanWithPublicConstructor(Bindable<JavaBeanWithPublicConstructor> bindable) {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo", "constructor");
    source.put("foo.value", "setter");
    this.sources.add(source);
    return this.binder.bindOrCreate("foo", bindable);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource)

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