From d44ffd3534d3c3ca4cb001570939d7b75982e463 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 9 May 2019 12:27:33 +0900 Subject: [PATCH 1/2] Add negative tests to ConfigurationPropertiesScanTests See gh-16758 --- .../ConfigurationPropertiesScanTests.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java index 43b632305f..82539783df 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java @@ -34,6 +34,7 @@ import static org.mockito.BDDMockito.willCallRealMethod; * Integration tests for {@link ConfigurationPropertiesScan}. * * @author Madhura Bhave + * @author Johnny Lim */ public class ConfigurationPropertiesScanTests { @@ -52,7 +53,7 @@ public class ConfigurationPropertiesScanTests { } @Test - public void scanImportBeanRegistrarShouldBeEnvironmentAware() { + public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithRequiredProfile() { this.context.getEnvironment().addActiveProfile("test"); load(TestConfiguration.class); assertThat(this.context.containsBean( @@ -61,7 +62,15 @@ public class ConfigurationPropertiesScanTests { } @Test - public void scanImportBeanRegistrarShouldBeResourceLoaderAware() { + public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithoutRequiredProfile() { + load(TestConfiguration.class); + assertThat(this.context.containsBean( + "profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties")) + .isFalse(); + } + + @Test + public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithRequiredResource() { DefaultResourceLoader resourceLoader = Mockito.mock(DefaultResourceLoader.class); this.context.setResourceLoader(resourceLoader); willCallRealMethod().given(resourceLoader).getClassLoader(); @@ -73,6 +82,14 @@ public class ConfigurationPropertiesScanTests { .isTrue(); } + @Test + public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithoutRequiredResource() { + load(TestConfiguration.class); + assertThat(this.context.containsBean( + "resource-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyResourceProperties")) + .isFalse(); + } + private void load(Class... classes) { this.context.register(classes); this.context.refresh(); From c85c653e57a702c90ca6527f05e295249ac9c99a Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 10 May 2019 10:22:34 +0200 Subject: [PATCH 2/2] Polish "Add negative tests to ConfigurationPropertiesScanTests" Closes gh-16758 --- .../context/properties/ConfigurationPropertiesScanTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java index 82539783df..7f478f2625 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanTests.java @@ -66,7 +66,7 @@ public class ConfigurationPropertiesScanTests { load(TestConfiguration.class); assertThat(this.context.containsBean( "profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties")) - .isFalse(); + .isFalse(); } @Test @@ -87,7 +87,7 @@ public class ConfigurationPropertiesScanTests { load(TestConfiguration.class); assertThat(this.context.containsBean( "resource-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyResourceProperties")) - .isFalse(); + .isFalse(); } private void load(Class... classes) {