Fix tests
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.boot.context.properties;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
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.boot.context.properties.scan.valid.ConfigurationPropertiesScanConfiguration;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
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.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
@@ -42,6 +44,11 @@ public class ConfigurationPropertiesScanRegistrarTests {
|
|||||||
|
|
||||||
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
this.registrar.setEnvironment(new MockEnvironment());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerBeanDefintionsShouldScanForConfigurationProperties()
|
public void registerBeanDefintionsShouldScanForConfigurationProperties()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ConfigurationPropertiesScanTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scanImportBeanRegistrarShouldBeEnvironmentAware() {
|
public void scanImportBeanRegistrarShouldBeEnvironmentAware() {
|
||||||
// this.context.getEnvironment().addActiveProfile("test");
|
this.context.getEnvironment().addActiveProfile("test");
|
||||||
load(TestConfiguration.class);
|
load(TestConfiguration.class);
|
||||||
assertThat(this.context.containsBean(
|
assertThat(this.context.containsBean(
|
||||||
"profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties"))
|
"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.ConditionContext;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,9 +48,7 @@ public class AScanConfiguration {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
ByteArrayResource resource = (ByteArrayResource) context.getResourceLoader()
|
return context.getResourceLoader().getResource("test").exists();
|
||||||
.getResource("test");
|
|
||||||
return (new String(resource.getByteArray())).equals("test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user