Commit fc8fdf2d authored by Phillip Webb's avatar Phillip Webb

Merge branch '2.3.x'

Closes gh-21656
parents 399d0f7b 2589f980
...@@ -104,7 +104,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { ...@@ -104,7 +104,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
} }
private static ConfigurationPropertyState containsDescendantOfForRandom(ConfigurationPropertyName name) { private static ConfigurationPropertyState containsDescendantOfForRandom(ConfigurationPropertyName name) {
if (name.isAncestorOf(RANDOM) || name.equals(RANDOM)) { if (RANDOM.isAncestorOf(name) || name.equals(RANDOM)) {
return ConfigurationPropertyState.PRESENT; return ConfigurationPropertyState.PRESENT;
} }
return ConfigurationPropertyState.ABSENT; return ConfigurationPropertyState.ABSENT;
......
...@@ -21,6 +21,7 @@ import java.util.Map; ...@@ -21,6 +21,7 @@ import java.util.Map;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.boot.origin.Origin; import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginLookup; import org.springframework.boot.origin.OriginLookup;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
...@@ -141,6 +142,30 @@ class SpringConfigurationPropertySourceTests { ...@@ -141,6 +142,30 @@ class SpringConfigurationPropertySourceTests {
.isInstanceOf(IterableConfigurationPropertySource.class); .isInstanceOf(IterableConfigurationPropertySource.class);
} }
@Test
void containsDescendantOfWhenRandomSourceAndRandomPropertyReturnsPresent() {
SpringConfigurationPropertySource source = SpringConfigurationPropertySource
.from(new RandomValuePropertySource());
assertThat(source.containsDescendantOf(ConfigurationPropertyName.of("random")))
.isEqualTo(ConfigurationPropertyState.PRESENT);
}
@Test
void containsDescendantOfWhenRandomSourceAndRandomPrefixedPropertyReturnsPresent() {
SpringConfigurationPropertySource source = SpringConfigurationPropertySource
.from(new RandomValuePropertySource());
assertThat(source.containsDescendantOf(ConfigurationPropertyName.of("random.something")))
.isEqualTo(ConfigurationPropertyState.PRESENT);
}
@Test
void containsDescendantOfWhenRandomSourceAndNonRandomPropertyReturnsAbsent() {
SpringConfigurationPropertySource source = SpringConfigurationPropertySource
.from(new RandomValuePropertySource());
assertThat(source.containsDescendantOf(ConfigurationPropertyName.of("abandon.something")))
.isEqualTo(ConfigurationPropertyState.ABSENT);
}
/** /**
* Test {@link PropertySource} that's also an {@link OriginLookup}. * Test {@link PropertySource} that's also an {@link OriginLookup}.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment