mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Fix containsDescendantOf for random sources
Fix the `containsDescendantOf` logic for random property sources to ensure that ancestors are correctly matched. Closes gh-21654
This commit is contained in:
parent
14e6c734a9
commit
09a47c9aad
@ -190,7 +190,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
|
||||
}
|
||||
|
||||
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.ABSENT;
|
||||
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.env.RandomValuePropertySource;
|
||||
import org.springframework.boot.origin.Origin;
|
||||
import org.springframework.boot.origin.OriginLookup;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
@ -148,6 +149,30 @@ class SpringConfigurationPropertySourceTests {
|
||||
.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}.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user