From d44ffd3534d3c3ca4cb001570939d7b75982e463 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 9 May 2019 12:27:33 +0900 Subject: [PATCH] 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();