Skip to content

Commit 555dd3b

Browse files
committed
Merge pull request #16758 from izeye
* pr/16758: Polish "Add negative tests to ConfigurationPropertiesScanTests" Add negative tests to ConfigurationPropertiesScanTests
2 parents 75eb0ef + c85c653 commit 555dd3b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Integration tests for {@link ConfigurationPropertiesScan}.
3535
*
3636
* @author Madhura Bhave
37+
* @author Johnny Lim
3738
*/
3839
public class ConfigurationPropertiesScanTests {
3940

@@ -52,7 +53,7 @@ public void teardown() {
5253
}
5354

5455
@Test
55-
public void scanImportBeanRegistrarShouldBeEnvironmentAware() {
56+
public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithRequiredProfile() {
5657
this.context.getEnvironment().addActiveProfile("test");
5758
load(TestConfiguration.class);
5859
assertThat(this.context.containsBean(
@@ -61,7 +62,15 @@ public void scanImportBeanRegistrarShouldBeEnvironmentAware() {
6162
}
6263

6364
@Test
64-
public void scanImportBeanRegistrarShouldBeResourceLoaderAware() {
65+
public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithoutRequiredProfile() {
66+
load(TestConfiguration.class);
67+
assertThat(this.context.containsBean(
68+
"profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties"))
69+
.isFalse();
70+
}
71+
72+
@Test
73+
public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithRequiredResource() {
6574
DefaultResourceLoader resourceLoader = Mockito.mock(DefaultResourceLoader.class);
6675
this.context.setResourceLoader(resourceLoader);
6776
willCallRealMethod().given(resourceLoader).getClassLoader();
@@ -73,6 +82,14 @@ public void scanImportBeanRegistrarShouldBeResourceLoaderAware() {
7382
.isTrue();
7483
}
7584

85+
@Test
86+
public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithoutRequiredResource() {
87+
load(TestConfiguration.class);
88+
assertThat(this.context.containsBean(
89+
"resource-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyResourceProperties"))
90+
.isFalse();
91+
}
92+
7693
private void load(Class<?>... classes) {
7794
this.context.register(classes);
7895
this.context.refresh();

0 commit comments

Comments
 (0)