diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java index eae0e120bd..cc76cc8176 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.context.properties; import java.io.IOException; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.config.BeanDefinition; @@ -27,6 +28,7 @@ import org.springframework.boot.context.properties.scan.invalid.d.OtherInvalidCo import org.springframework.boot.context.properties.scan.valid.ConfigurationPropertiesScanConfiguration; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; +import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -42,6 +44,11 @@ public class ConfigurationPropertiesScanRegistrarTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + @Before + public void setup() { + this.registrar.setEnvironment(new MockEnvironment()); + } + @Test public void registerBeanDefintionsShouldScanForConfigurationProperties() throws IOException { 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 96e996134d..43b632305f 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 @@ -53,7 +53,7 @@ public class ConfigurationPropertiesScanTests { @Test public void scanImportBeanRegistrarShouldBeEnvironmentAware() { - // this.context.getEnvironment().addActiveProfile("test"); + this.context.getEnvironment().addActiveProfile("test"); load(TestConfiguration.class); assertThat(this.context.containsBean( "profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties")) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/a/AScanConfiguration.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/a/AScanConfiguration.java index dafebc3583..09a3f15df1 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/a/AScanConfiguration.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/scan/valid/a/AScanConfiguration.java @@ -20,7 +20,6 @@ import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Profile; -import org.springframework.core.io.ByteArrayResource; import org.springframework.core.type.AnnotatedTypeMetadata; /** @@ -49,9 +48,7 @@ public class AScanConfiguration { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - ByteArrayResource resource = (ByteArrayResource) context.getResourceLoader() - .getResource("test"); - return (new String(resource.getByteArray())).equals("test"); + return context.getResourceLoader().getResource("test").exists(); } }