Skip to content

Commit f4ed4d1

Browse files
committed
Add failing tests
1 parent b7b43af commit f4ed4d1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/StandardConfigDataLocationResolverTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.boot.context.properties.bind.Binder;
2727
import org.springframework.boot.env.PropertiesPropertySourceLoader;
2828
import org.springframework.boot.logging.DeferredLogs;
29+
import org.springframework.core.env.Environment;
2930
import org.springframework.core.env.PropertySource;
3031
import org.springframework.core.io.ClassPathResource;
3132
import org.springframework.core.io.DefaultResourceLoader;
@@ -372,6 +373,28 @@ void resolveProfileSpecificWhenProfileContainsInvalidCharactersThrowsException()
372373
"Invalid profile 'dev*test': must contain only letters or digits or '-' or '_'");
373374
}
374375

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+
375398
private String filePath(String... components) {
376399
return "file [" + String.join(File.separator, components) + "]";
377400
}

0 commit comments

Comments
 (0)