Skip to content

Commit d5de29b

Browse files
author
Dave Syer
committed
Add test case for profile ordering
The command line profile (or equivalently System property) is not winning right now. Arguably that should be fixed. (Thinking...) Relevant to gh-342
1 parent 05fd50d commit d5de29b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import static org.hamcrest.Matchers.is;
6060
import static org.hamcrest.Matchers.sameInstance;
6161
import static org.hamcrest.Matchers.startsWith;
62+
import static org.junit.Assert.assertArrayEquals;
6263
import static org.junit.Assert.assertEquals;
6364
import static org.junit.Assert.assertFalse;
6465
import static org.junit.Assert.assertNotNull;
@@ -277,15 +278,37 @@ public void proprtiesFileEnhancesEnvironment() throws Exception {
277278
assertEquals("bucket", environment.getProperty("foo"));
278279
}
279280

281+
@Test
282+
public void addProfiles() throws Exception {
283+
SpringApplication application = new SpringApplication(ExampleConfig.class);
284+
application.setWebEnvironment(false);
285+
application.setAdditionalProfiles("foo");
286+
ConfigurableEnvironment environment = new StandardEnvironment();
287+
application.setEnvironment(environment);
288+
application.run();
289+
assertTrue(environment.acceptsProfiles("foo"));
290+
}
291+
292+
@Test
293+
public void addProfilesOrder() throws Exception {
294+
SpringApplication application = new SpringApplication(ExampleConfig.class);
295+
application.setWebEnvironment(false);
296+
application.setAdditionalProfiles("foo");
297+
ConfigurableEnvironment environment = new StandardEnvironment();
298+
application.setEnvironment(environment);
299+
application.run("--spring.profiles.active=bar");
300+
// Command line arguably should always come last (not the case currently)
301+
assertArrayEquals(new String[] { "bar", "foo" }, environment.getActiveProfiles());
302+
}
303+
280304
@Test
281305
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
282306
SpringApplication application = new SpringApplication(ExampleConfig.class);
283307
application.setWebEnvironment(false);
284308
ConfigurableEnvironment environment = new StandardEnvironment();
285309
application.setEnvironment(environment);
286310
application.run();
287-
assertFalse(hasPropertySource(environment, PropertySource.class,
288-
"commandLineArgs"));
311+
assertEquals("bucket", environment.getProperty("foo"));
289312
}
290313

291314
@Test

0 commit comments

Comments
 (0)