|
59 | 59 | import static org.hamcrest.Matchers.is;
|
60 | 60 | import static org.hamcrest.Matchers.sameInstance;
|
61 | 61 | import static org.hamcrest.Matchers.startsWith;
|
| 62 | +import static org.junit.Assert.assertArrayEquals; |
62 | 63 | import static org.junit.Assert.assertEquals;
|
63 | 64 | import static org.junit.Assert.assertFalse;
|
64 | 65 | import static org.junit.Assert.assertNotNull;
|
@@ -277,15 +278,37 @@ public void proprtiesFileEnhancesEnvironment() throws Exception {
|
277 | 278 | assertEquals("bucket", environment.getProperty("foo"));
|
278 | 279 | }
|
279 | 280 |
|
| 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 | + |
280 | 304 | @Test
|
281 | 305 | public void emptyCommandLinePropertySourceNotAdded() throws Exception {
|
282 | 306 | SpringApplication application = new SpringApplication(ExampleConfig.class);
|
283 | 307 | application.setWebEnvironment(false);
|
284 | 308 | ConfigurableEnvironment environment = new StandardEnvironment();
|
285 | 309 | application.setEnvironment(environment);
|
286 | 310 | application.run();
|
287 |
| - assertFalse(hasPropertySource(environment, PropertySource.class, |
288 |
| - "commandLineArgs")); |
| 311 | + assertEquals("bucket", environment.getProperty("foo")); |
289 | 312 | }
|
290 | 313 |
|
291 | 314 | @Test
|
|
0 commit comments