Fix tests

pull/16622/head
Madhura Bhave 6 years ago
parent 9fb65e57c0
commit 5c2a7e61d0

@ -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 {

@ -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"))

@ -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();
}
}

Loading…
Cancel
Save