Introduce ConfigurableEnvironment#addActiveProfile

Provides a convenient mechanism for activating an additional profile
while preserving those that are already active, as opposed to
calling #setActiveProfiles with the contents of #getActiveProfiles plus
the new profile.

Issue: SPR-8548
This commit is contained in:
Chris Beams
2011-08-20 03:02:20 +00:00
parent c0eeb8bacd
commit 76bf72c9f8
3 changed files with 39 additions and 5 deletions

View File

@@ -120,6 +120,21 @@ public class EnvironmentTests {
environment.setDefaultProfiles("");
}
@Test
public void addActiveProfile() {
assertThat(environment.getActiveProfiles().length, is(0));
environment.setActiveProfiles("local", "embedded");
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("local", "embedded"));
assertThat(environment.getActiveProfiles().length, is(2));
environment.addActiveProfile("p1");
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p1"));
assertThat(environment.getActiveProfiles().length, is(3));
environment.addActiveProfile("p2");
environment.addActiveProfile("p3");
assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p2", "p3"));
assertThat(environment.getActiveProfiles().length, is(5));
}
@Test
public void reservedDefaultProfile() {
assertThat(environment.getDefaultProfiles(), equalTo(new String[]{RESERVED_DEFAULT_PROFILE_NAME}));