|
|
|
@ -16,11 +16,11 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.context.properties.source;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.mockito.Answers;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.origin.Origin;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
@ -107,31 +107,19 @@ public class AliasedConfigurationPropertySourceTests {
|
|
|
|
|
.willReturn(ConfigurationPropertyState.ABSENT);
|
|
|
|
|
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
|
|
|
|
|
.willReturn(ConfigurationPropertyState.PRESENT);
|
|
|
|
|
ConfigurationPropertyName barBar = ConfigurationPropertyName.of("bar.bar");
|
|
|
|
|
given(source.getConfigurationProperty(barBar)).willReturn(
|
|
|
|
|
new ConfigurationProperty(barBar, "barBarValue", mock(Origin.class)));
|
|
|
|
|
ConfigurationPropertySource aliased = source
|
|
|
|
|
.withAliases(new ConfigurationPropertyNameAliases("bar.bar", "foo.foo"));
|
|
|
|
|
.withAliases(new ConfigurationPropertyNameAliases("foo", "bar"));
|
|
|
|
|
assertThat(aliased.containsDescendantOf(name))
|
|
|
|
|
.isEqualTo(ConfigurationPropertyState.PRESENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void containsDescendantOfWhenPresentInAliasShouldReturnPresent() {
|
|
|
|
|
ConfigurationPropertyName name = ConfigurationPropertyName.of("baz");
|
|
|
|
|
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
|
|
|
|
|
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
|
|
|
|
|
given(source.containsDescendantOf(name))
|
|
|
|
|
.willReturn(ConfigurationPropertyState.ABSENT);
|
|
|
|
|
|
|
|
|
|
ConfigurationPropertyName barFoo = ConfigurationPropertyName.of("bar.foo");
|
|
|
|
|
|
|
|
|
|
given(source.getConfigurationProperty(barFoo)).willReturn(
|
|
|
|
|
new ConfigurationProperty(barFoo, "barFooValue", mock(Origin.class)));
|
|
|
|
|
|
|
|
|
|
ConfigurationPropertySource source = new MapConfigurationPropertySource(
|
|
|
|
|
Collections.singletonMap("foo.bar", "foobar"));
|
|
|
|
|
ConfigurationPropertySource aliased = source
|
|
|
|
|
.withAliases(new ConfigurationPropertyNameAliases("bar.foo", "baz.foo"));
|
|
|
|
|
assertThat(aliased.containsDescendantOf(name))
|
|
|
|
|
.withAliases(new ConfigurationPropertyNameAliases("foo.bar", "baz.foo"));
|
|
|
|
|
assertThat(aliased.containsDescendantOf(ConfigurationPropertyName.of("baz")))
|
|
|
|
|
.isEqualTo(ConfigurationPropertyState.PRESENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|