Search in sources :

Example 1 with MockConfigurationPropertySource

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

the class IgnoreTopLevelConverterNotFoundBindHandlerTests method setup.

@BeforeEach
void setup() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("example", "bar");
    this.sources.add(source);
    this.binder = new Binder(this.sources);
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MockConfigurationPropertySource

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

the class PackagePrivateBeanBindingTests method bindToPackagePrivateClassShouldBindToInstance.

@Test
void bindToPackagePrivateClassShouldBindToInstance() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.bar", "999");
    this.sources.add(source);
    ExamplePackagePrivateBean bean = this.binder.bind(this.name, Bindable.of(ExamplePackagePrivateBean.class)).get();
    assertThat(bean.getBar()).isEqualTo(999);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 3 with MockConfigurationPropertySource

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

the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerThrowException.

@Test
void bindWhenUsingNoUnboundElementsHandlerThrowException() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("example.foo", "bar");
    source.put("example.baz", "bar");
    this.sources.add(source);
    this.binder = new Binder(this.sources);
    assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler())).satisfies((ex) -> assertThat(ex.getCause().getMessage()).contains("The elements [example.baz] were left unbound"));
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 4 with MockConfigurationPropertySource

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

the class NoUnboundElementsBindHandlerTests method bindWhenNotUsingNoUnboundElementsHandlerShouldBind.

@Test
void bindWhenNotUsingNoUnboundElementsHandlerShouldBind() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("example.foo", "bar");
    source.put("example.baz", "bar");
    this.sources.add(source);
    this.binder = new Binder(this.sources);
    Example bound = this.binder.bind(ConfigurationPropertyName.of("example"), Bindable.of(Example.class)).get();
    assertThat(bound.getFoo()).isEqualTo("bar");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 5 with MockConfigurationPropertySource

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

the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBind.

@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBind() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("example.foo", "bar");
    this.sources.add(source);
    this.binder = new Binder(this.sources);
    Example bound = this.binder.bind("example", Bindable.of(Example.class), new NoUnboundElementsBindHandler()).get();
    assertThat(bound.getFoo()).isEqualTo("bar");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) 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