Replace usages of EnvironmentTestUtils

This commit is contained in:
Madhura Bhave
2017-05-23 10:05:43 -07:00
parent 05254fe322
commit d745b69630
156 changed files with 863 additions and 883 deletions

View File

@@ -23,7 +23,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -49,8 +49,8 @@ public class SamplePropertyValidationApplicationTests {
@Test
public void bindValidProperties() {
this.context.register(SamplePropertyValidationApplication.class);
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1",
"sample.port:9090");
TestPropertyValues.of("sample.host:192.168.0.1",
"sample.port:9090").applyTo(this.context);
this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class);
assertThat(properties.getHost()).isEqualTo("192.168.0.1");
@@ -60,8 +60,8 @@ public class SamplePropertyValidationApplicationTests {
@Test
public void bindInvalidHost() {
this.context.register(SamplePropertyValidationApplication.class);
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:xxxxxx",
"sample.port:9090");
TestPropertyValues.of("sample.host:xxxxxx",
"sample.port:9090").applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Failed to bind properties under 'sample'");
this.context.refresh();
@@ -79,8 +79,8 @@ public class SamplePropertyValidationApplicationTests {
public void validatorOnlyCalledOnSupportedClass() {
this.context.register(SamplePropertyValidationApplication.class);
this.context.register(ServerProperties.class); // our validator will not apply
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1",
"sample.port:9090");
TestPropertyValues.of("sample.host:192.168.0.1",
"sample.port:9090").applyTo(this.context);
this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class);
assertThat(properties.getHost()).isEqualTo("192.168.0.1");