PropertySourcesPlaceholdersResolverTests Class — spring-boot Architecture
Architecture documentation for the PropertySourcesPlaceholdersResolverTests class in PropertySourcesPlaceholdersResolverTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/PropertySourcesPlaceholdersResolverTests.java lines 40–99
class PropertySourcesPlaceholdersResolverTests {
private @Nullable PropertySourcesPlaceholdersResolver resolver;
@Test
@SuppressWarnings("NullAway") // Test null check
void placeholderResolverIfEnvironmentNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new PropertySourcesPlaceholdersResolver((Environment) null))
.withMessageContaining("'environment' must not be null");
}
@Test
void resolveIfPlaceholderPresentResolvesProperty() {
MutablePropertySources sources = getPropertySources();
this.resolver = new PropertySourcesPlaceholdersResolver(sources);
Object resolved = this.resolver.resolvePlaceholders("${FOO}");
assertThat(resolved).isEqualTo("hello world");
}
@Test
void resolveIfPlaceholderAbsentUsesDefault() {
this.resolver = new PropertySourcesPlaceholdersResolver((PropertySources) null);
Object resolved = this.resolver.resolvePlaceholders("${FOO:bar}");
assertThat(resolved).isEqualTo("bar");
}
@Test
void resolveIfPlaceholderAbsentAndNoDefaultUsesPlaceholder() {
this.resolver = new PropertySourcesPlaceholdersResolver((PropertySources) null);
Object resolved = this.resolver.resolvePlaceholders("${FOO}");
assertThat(resolved).isEqualTo("${FOO}");
}
@Test
void resolveIfHelperPresentShouldUseIt() {
MutablePropertySources sources = getPropertySources();
TestPropertyPlaceholderHelper helper = new TestPropertyPlaceholderHelper("$<", ">");
this.resolver = new PropertySourcesPlaceholdersResolver(sources, helper);
Object resolved = this.resolver.resolvePlaceholders("$<FOO>");
assertThat(resolved).isEqualTo("hello world");
}
private MutablePropertySources getPropertySources() {
MutablePropertySources sources = new MutablePropertySources();
Map<String, Object> source = new HashMap<>();
source.put("FOO", "hello world");
sources.addFirst(new MapPropertySource("test", source));
return sources;
}
static class TestPropertyPlaceholderHelper extends PropertyPlaceholderHelper {
TestPropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix) {
super(placeholderPrefix, placeholderSuffix);
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free