Allow bypass of active/default properties
Introduce protected methods that can be used to bypass or change the way that active and default property values are read. See gh-26461
This commit is contained in:
committed by
Stephane Nicoll
parent
9c6b1b645d
commit
da3ff29e88
@@ -18,6 +18,8 @@ package org.springframework.core.env;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -105,6 +107,30 @@ class CustomEnvironmentTests {
|
||||
assertThat(env.acceptsProfiles(Profiles.of("a1 | a2"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNoProfileProperties() {
|
||||
ConfigurableEnvironment env = new AbstractEnvironment() {
|
||||
|
||||
@Override
|
||||
protected String doGetActiveProfilesProperty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doGetDefaultProfilesProperty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Map<String, Object> values = new LinkedHashMap<>();
|
||||
values.put(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "a,b,c");
|
||||
values.put(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, "d,e,f");
|
||||
PropertySource<?> propertySource = new MapPropertySource("test", values);
|
||||
env.getPropertySources().addFirst(propertySource);
|
||||
assertThat(env.getActiveProfiles()).isEmpty();
|
||||
assertThat(env.getDefaultProfiles()).containsExactly(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME);
|
||||
}
|
||||
|
||||
private Profiles defaultProfile() {
|
||||
return Profiles.of(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user