Search in sources :

Example 1 with ExampleEnum

use of org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum in project spring-boot by spring-projects.

the class MapBinderTests method bindToMapWithPlaceholdersShouldBeGreedyForScalars.

@Test
void bindToMapWithPlaceholdersShouldBeGreedyForScalars() {
    StandardEnvironment environment = new StandardEnvironment();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, "foo=boo");
    MockConfigurationPropertySource source = new MockConfigurationPropertySource("foo.aaa.bbb.ccc", "baz-${foo}");
    this.sources.add(source);
    this.binder = new Binder(this.sources, new PropertySourcesPlaceholdersResolver(environment));
    Map<String, ExampleEnum> result = this.binder.bind("foo", Bindable.mapOf(String.class, ExampleEnum.class)).get();
    assertThat(result).containsEntry("aaa.bbb.ccc", ExampleEnum.BAZ_BOO);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) ExampleEnum(org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum) Test(org.junit.jupiter.api.Test)

Example 2 with ExampleEnum

use of org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum in project spring-boot by spring-projects.

the class MapBinderTests method bindToMapShouldBeGreedyForScalars.

@Test
void bindToMapShouldBeGreedyForScalars() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.aaa.bbb.ccc", "foo-bar");
    source.put("foo.bbb.ccc.ddd", "BAR_BAZ");
    source.put("foo.ccc.ddd.eee", "bazboo");
    this.sources.add(source);
    Map<String, ExampleEnum> result = this.binder.bind("foo", Bindable.mapOf(String.class, ExampleEnum.class)).get();
    assertThat(result).hasSize(3);
    assertThat(result).containsEntry("aaa.bbb.ccc", ExampleEnum.FOO_BAR);
    assertThat(result).containsEntry("bbb.ccc.ddd", ExampleEnum.BAR_BAZ);
    assertThat(result).containsEntry("ccc.ddd.eee", ExampleEnum.BAZ_BOO);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ExampleEnum(org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 ExampleEnum (org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum)2 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)2 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1