|
26 | 26 | import org.springframework.boot.context.properties.bind.Binder;
|
27 | 27 | import org.springframework.boot.env.PropertiesPropertySourceLoader;
|
28 | 28 | import org.springframework.boot.logging.DeferredLogs;
|
| 29 | +import org.springframework.core.env.Environment; |
29 | 30 | import org.springframework.core.env.PropertySource;
|
30 | 31 | import org.springframework.core.io.ClassPathResource;
|
31 | 32 | import org.springframework.core.io.DefaultResourceLoader;
|
@@ -372,6 +373,28 @@ void resolveProfileSpecificWhenProfileContainsInvalidCharactersThrowsException()
|
372 | 373 | "Invalid profile 'dev*test': must contain only letters or digits or '-' or '_'");
|
373 | 374 | }
|
374 | 375 |
|
| 376 | + @Test |
| 377 | + void resolveProfileSpecific_WhenProfileContainsEmptyString_ThrowsException() { |
| 378 | + ConfigDataLocation location = ConfigDataLocation.of("classpath:/configdata/properties/"); |
| 379 | + Environment mockEnv = mock(Environment.class); |
| 380 | + given(mockEnv.getActiveProfiles()).willReturn(new String[]{" "}); |
| 381 | + Profiles profiles = new Profiles(mockEnv, this.environmentBinder, Collections.emptyList()); |
| 382 | + assertThatIllegalStateException() |
| 383 | + .isThrownBy(() -> this.resolver.resolveProfileSpecific(this.context, location, profiles)) |
| 384 | + .withMessageStartingWith("Profile must contain text"); |
| 385 | + } |
| 386 | + |
| 387 | + @Test |
| 388 | + void resolveProfileSpecific_WhenProfileIsNull_ThrowsException() { |
| 389 | + ConfigDataLocation location = ConfigDataLocation.of("classpath:/configdata/properties/"); |
| 390 | + Environment mockEnv = mock(Environment.class); |
| 391 | + given(mockEnv.getActiveProfiles()).willReturn(null); |
| 392 | + Profiles profiles = new Profiles(mockEnv, this.environmentBinder, Collections.emptyList()); |
| 393 | + assertThatIllegalStateException() |
| 394 | + .isThrownBy(() -> this.resolver.resolveProfileSpecific(this.context, location, profiles)) |
| 395 | + .withMessageStartingWith("Profile must contain text"); |
| 396 | + } |
| 397 | + |
375 | 398 | private String filePath(String... components) {
|
376 | 399 | return "file [" + String.join(File.separator, components) + "]";
|
377 | 400 | }
|
|
0 commit comments