diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/LifecycleMvcAutoConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/LifecycleMvcAutoConfigurationTests.java index 4aa569c4..f6f44a8e 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/LifecycleMvcAutoConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/autoconfigure/LifecycleMvcAutoConfigurationTests.java @@ -1,7 +1,6 @@ package org.springframework.cloud.autoconfigure; import java.util.List; -import java.util.concurrent.Callable; import java.util.function.Function; import org.assertj.core.util.Lists; diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java index 6a74de42..fe151f9c 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java @@ -47,7 +47,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.springframework.boot.WebApplicationType.NONE; /** * @author Dave Syer diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapListenerHierarchyIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapListenerHierarchyIntegrationTests.java index 61d8f3cd..1cb291a1 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapListenerHierarchyIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapListenerHierarchyIntegrationTests.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertNull; import static org.springframework.boot.WebApplicationType.NONE; import org.junit.Test; -import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfigurationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfigurationTests.java index 070162bc..49d7fa6d 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfigurationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EncryptionBootstrapConfigurationTests.java @@ -46,7 +46,7 @@ public class EncryptionBootstrapConfigurationTests { public void nonExistentKeystoreLocationShouldNotBeAllowed() { try { new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class) - .web(false) + .web(WebApplicationType.NONE) .properties("encrypt.key-store.location:classpath:/server.jks1", "encrypt.key-store.password:letmein", "encrypt.key-store.alias:mytestkey", diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java index 8a1567ea..06a2c8ea 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationInitializerTests.java @@ -15,10 +15,19 @@ */ package org.springframework.cloud.bootstrap.encrypt; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.DECRYPTED_PROPERTY_SOURCE_NAME; + import java.util.Collections; import java.util.Map; import org.junit.Test; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.test.util.TestPropertyValues.Type; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -28,14 +37,6 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.security.crypto.encrypt.Encryptors; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment; -import static org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.DECRYPTED_PROPERTY_SOURCE_NAME; - /** * @author Dave Syer * @author Biju Kunjummen @@ -48,7 +49,7 @@ public class EnvironmentDecryptApplicationInitializerTests { @Test public void decryptCipherKey() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - addEnvironment(context, "foo: {cipher}bar"); + TestPropertyValues.of("foo: {cipher}bar").applyTo(context); this.listener.initialize(context); assertEquals("bar", context.getEnvironment().getProperty("foo")); } @@ -56,7 +57,7 @@ public class EnvironmentDecryptApplicationInitializerTests { @Test public void relaxedBinding() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - addEnvironment(context, "FOO_TEXT: {cipher}bar"); + TestPropertyValues.of("FOO_TEXT: {cipher}bar").applyTo(context); this.listener.initialize(context); assertEquals("bar", context.getEnvironment().getProperty("foo.text")); } @@ -64,10 +65,10 @@ public class EnvironmentDecryptApplicationInitializerTests { @Test public void propertySourcesOrderedCorrectly() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - addEnvironment(context, "foo: {cipher}bar"); - context.getEnvironment().getPropertySources().addFirst(new MapPropertySource( - "test_override", - Collections. singletonMap("foo", "{cipher}spam"))); + TestPropertyValues.of("foo: {cipher}bar").applyTo(context); + context.getEnvironment().getPropertySources() + .addFirst(new MapPropertySource("test_override", + Collections.singletonMap("foo", "{cipher}spam"))); this.listener.initialize(context); assertEquals("spam", context.getEnvironment().getProperty("foo")); } @@ -77,7 +78,7 @@ public class EnvironmentDecryptApplicationInitializerTests { this.listener = new EnvironmentDecryptApplicationInitializer( Encryptors.text("deadbeef", "AFFE37")); ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - addEnvironment(context, "foo: {cipher}bar"); + TestPropertyValues.of("foo: {cipher}bar").applyTo(context); this.listener.initialize(context); assertEquals("bar", context.getEnvironment().getProperty("foo")); } @@ -88,7 +89,7 @@ public class EnvironmentDecryptApplicationInitializerTests { Encryptors.text("deadbeef", "AFFE37")); this.listener.setFailOnError(false); ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - addEnvironment(context, "foo: {cipher}bar"); + TestPropertyValues.of("foo: {cipher}bar").applyTo(context); this.listener.initialize(context); // Empty is safest fallback for undecryptable cipher assertEquals("", context.getEnvironment().getProperty("foo")); @@ -98,35 +99,44 @@ public class EnvironmentDecryptApplicationInitializerTests { @SuppressWarnings("unchecked") public void indexedPropertiesCopied() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - // tests that collections in another property source don't get copied into "decrypted" property source - addEnvironment(context, "yours[0].someValue: yourFoo", "yours[1].someValue: yourBar"); + // tests that collections in another property source don't get copied into + // "decrypted" property source + TestPropertyValues + .of("yours[0].someValue: yourFoo", "yours[1].someValue: yourBar") + .applyTo(context); // collection with some encrypted keys and some not encrypted - addEnvironment("combinedTest", context.getEnvironment(), "mine[0].someValue: Foo", + TestPropertyValues + .of("mine[0].someValue: Foo", "mine[0].someKey: {cipher}Foo0", "mine[1].someValue: Bar", - "mine[1].someKey: {cipher}Bar1", "nonindexed: nonindexval"); + "mine[1].someKey: {cipher}Bar1", "nonindexed: nonindexval") + .applyTo(context.getEnvironment(), Type.MAP, "combinedTest"); this.listener.initialize(context); - assertEquals("Foo", context.getEnvironment().getProperty("mine[0].someValue")); + assertEquals("Foo", context.getEnvironment().getProperty("mine[0].someValue")); assertEquals("Foo0", context.getEnvironment().getProperty("mine[0].someKey")); - assertEquals("Bar", context.getEnvironment().getProperty("mine[1].someValue")); + assertEquals("Bar", context.getEnvironment().getProperty("mine[1].someValue")); assertEquals("Bar1", context.getEnvironment().getProperty("mine[1].someKey")); - assertEquals("yourFoo", context.getEnvironment().getProperty("yours[0].someValue")); - assertEquals("yourBar", context.getEnvironment().getProperty("yours[1].someValue")); + assertEquals("yourFoo", + context.getEnvironment().getProperty("yours[0].someValue")); + assertEquals("yourBar", + context.getEnvironment().getProperty("yours[1].someValue")); - MutablePropertySources propertySources = context.getEnvironment().getPropertySources(); - PropertySource decrypted = (PropertySource) propertySources.get(DECRYPTED_PROPERTY_SOURCE_NAME); - assertThat("decrypted property source had wrong size", decrypted.getSource().size(), is(4)); + MutablePropertySources propertySources = context.getEnvironment() + .getPropertySources(); + PropertySource> decrypted = (PropertySource>) propertySources + .get(DECRYPTED_PROPERTY_SOURCE_NAME); + assertThat("decrypted property source had wrong size", + decrypted.getSource().size(), is(4)); } @Test public void testDecryptNonStandardParent() { ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(); - EnvironmentDecryptApplicationInitializer initializer = - new EnvironmentDecryptApplicationInitializer(Encryptors.noOpText()); - - addEnvironment(ctx, "key:{cipher}value"); + EnvironmentDecryptApplicationInitializer initializer = new EnvironmentDecryptApplicationInitializer( + Encryptors.noOpText()); + TestPropertyValues.of("key:{cipher}value").applyTo(ctx); ApplicationContext ctxParent = mock(ApplicationContext.class); when(ctxParent.getEnvironment()).thenReturn(mock(Environment.class)); diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/environment/EnvironmentManagerTest.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/environment/EnvironmentManagerTest.java index 518afe74..13373141 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/environment/EnvironmentManagerTest.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/environment/EnvironmentManagerTest.java @@ -1,19 +1,18 @@ package org.springframework.cloud.context.environment; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.mock.env.MockEnvironment; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - public class EnvironmentManagerTest { @Test diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java index 5612285d..a4587ac0 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderIntegrationTests.java @@ -15,17 +15,18 @@ */ package org.springframework.cloud.context.properties; +import static org.junit.Assert.assertEquals; + import javax.annotation.PostConstruct; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderIntegrationTests.TestConfiguration; @@ -36,8 +37,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertEquals; - @RunWith(SpringRunner.class) @SpringBootTest(classes = TestConfiguration.class) public class ConfigurationPropertiesRebinderIntegrationTests { @@ -57,7 +56,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests { assertEquals("Hello scope!", this.properties.getMessage()); assertEquals(2, this.properties.getCount()); // Change the dynamic property source... - EnvironmentTestUtils.addEnvironment(this.environment, "message:Foo"); + TestPropertyValues.of("message:Foo").applyTo(this.environment); // ...but don't refresh, so the bean stays the same: assertEquals("Hello scope!", this.properties.getMessage()); assertEquals(2, this.properties.getCount()); @@ -69,7 +68,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests { assertEquals(2, this.properties.getCount()); assertEquals("Hello scope!", this.properties.getMessage()); // Change the dynamic property source... - EnvironmentTestUtils.addEnvironment(this.environment, "message:Foo"); + TestPropertyValues.of("message:Foo").applyTo(this.environment); // ...and then refresh, so the bean is re-initialized: this.rebinder.rebind(); assertEquals("Foo", this.properties.getMessage()); @@ -82,7 +81,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests { assertEquals(2, this.properties.getCount()); assertEquals("Hello scope!", this.properties.getMessage()); // Change the dynamic property source... - EnvironmentTestUtils.addEnvironment(this.environment, "message:Foo"); + TestPropertyValues.of("message:Foo").applyTo(this.environment); // ...and then refresh, so the bean is re-initialized: this.rebinder.rebind("properties"); assertEquals("Foo", this.properties.getMessage()); diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderListIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderListIntegrationTests.java index b3f17119..a11e9f7b 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderListIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderListIntegrationTests.java @@ -15,6 +15,8 @@ */ package org.springframework.cloud.context.properties; +import static org.junit.Assert.assertEquals; + import java.util.List; import java.util.Map; @@ -23,13 +25,12 @@ import javax.annotation.PostConstruct; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderListIntegrationTests.TestConfiguration; @@ -41,8 +42,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertEquals; - @RunWith(SpringRunner.class) @SpringBootTest(classes = TestConfiguration.class, properties = "messages=one,two") @@ -61,7 +60,7 @@ public class ConfigurationPropertiesRebinderListIntegrationTests { @DirtiesContext public void testAppendProperties() throws Exception { assertEquals("[one, two]", this.properties.getMessages().toString()); - EnvironmentTestUtils.addEnvironment(this.environment, "messages[0]:foo"); + TestPropertyValues.of("messages[0]:foo").applyTo(this.environment); this.rebinder.rebind(); assertEquals("[foo]", this.properties.getMessages().toString()); } @@ -73,7 +72,7 @@ public class ConfigurationPropertiesRebinderListIntegrationTests { assertEquals("[one, two]", this.properties.getMessages().toString()); Map map = findTestProperties(); map.clear(); - EnvironmentTestUtils.addEnvironment(this.environment, "messages[0]:foo"); + TestPropertyValues.of("messages[0]:foo").applyTo(this.environment); this.rebinder.rebind(); assertEquals("[foo]", this.properties.getMessages().toString()); } @@ -95,7 +94,7 @@ public class ConfigurationPropertiesRebinderListIntegrationTests { assertEquals("[one, two]", this.properties.getMessages().toString()); Map map = findTestProperties(); map.clear(); - EnvironmentTestUtils.addEnvironment(this.environment, "messages:foo"); + TestPropertyValues.of("messages:foo").applyTo(this.environment); this.rebinder.rebind(); assertEquals("[foo]", this.properties.getMessages().toString()); } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderProxyIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderProxyIntegrationTests.java index bbf7f194..7dfca19a 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderProxyIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinderProxyIntegrationTests.java @@ -15,6 +15,8 @@ */ package org.springframework.cloud.context.properties; +import static org.junit.Assert.assertEquals; + import java.util.HashMap; import java.util.Map; @@ -22,14 +24,13 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration; import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinderProxyIntegrationTests.TestConfiguration; @@ -40,8 +41,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertEquals; - @RunWith(SpringRunner.class) @SpringBootTest(classes = TestConfiguration.class, properties = { "messages.expiry.one=168", "messages.expiry.two=76" }) @@ -62,7 +61,7 @@ public class ConfigurationPropertiesRebinderProxyIntegrationTests { // This comes out as a String not Integer if the rebinder processes the proxy // instead of the target assertEquals(new Integer(168), this.properties.getExpiry().get("one")); - EnvironmentTestUtils.addEnvironment(this.environment, "messages.expiry.one=56"); + TestPropertyValues.of("messages.expiry.one=56").applyTo(this.environment); this.rebinder.rebind(); assertEquals(new Integer(56), this.properties.getExpiry().get("one")); } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeListBindingIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeListBindingIntegrationTests.java index 2e73f628..2b5078cf 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeListBindingIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeListBindingIntegrationTests.java @@ -16,11 +16,13 @@ package org.springframework.cloud.context.scope.refresh; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; @@ -42,9 +44,6 @@ import org.springframework.jmx.export.annotation.ManagedResource; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(SpringRunner.class) @SpringBootTest(classes = TestConfiguration.class, properties = {"test.messages[0]=one","test.messages[1]=two"}) diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/endpoint/RefreshEndpointTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/endpoint/RefreshEndpointTests.java index e5825f9a..80b79276 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/endpoint/RefreshEndpointTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/endpoint/RefreshEndpointTests.java @@ -16,6 +16,10 @@ package org.springframework.cloud.endpoint; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; @@ -25,11 +29,10 @@ import java.util.Map; import org.junit.After; import org.junit.Test; - import org.springframework.boot.Banner.Mode; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.refresh.ContextRefresher; @@ -46,10 +49,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * @author Dave Syer * @author Venil Noronha @@ -67,12 +66,12 @@ public class RefreshEndpointTests { @Test public void keysComputedWhenAdded() throws Exception { - this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE) - .bannerMode(Mode.OFF).properties("spring.cloud.bootstrap.name:none") - .run(); + this.context = new SpringApplicationBuilder(Empty.class) + .web(WebApplicationType.NONE).bannerMode(Mode.OFF) + .properties("spring.cloud.bootstrap.name:none").run(); RefreshScope scope = new RefreshScope(); scope.setApplicationContext(this.context); - EnvironmentTestUtils.addEnvironment(this.context, "spring.profiles.active=local"); + TestPropertyValues.of("spring.profiles.active=local").applyTo(this.context); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection keys = endpoint.refresh(); @@ -81,13 +80,12 @@ public class RefreshEndpointTests { @Test public void keysComputedWhenOveridden() throws Exception { - this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE) - .bannerMode(Mode.OFF).properties("spring.cloud.bootstrap.name:none") - .run(); + this.context = new SpringApplicationBuilder(Empty.class) + .web(WebApplicationType.NONE).bannerMode(Mode.OFF) + .properties("spring.cloud.bootstrap.name:none").run(); RefreshScope scope = new RefreshScope(); scope.setApplicationContext(this.context); - EnvironmentTestUtils.addEnvironment(this.context, - "spring.profiles.active=override"); + TestPropertyValues.of("spring.profiles.active=override").applyTo(this.context); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection keys = endpoint.refresh(); @@ -96,14 +94,15 @@ public class RefreshEndpointTests { @Test public void keysComputedWhenChangesInExternalProperties() throws Exception { - this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE) - .bannerMode(Mode.OFF).properties("spring.cloud.bootstrap.name:none") - .run(); + this.context = new SpringApplicationBuilder(Empty.class) + .web(WebApplicationType.NONE).bannerMode(Mode.OFF) + .properties("spring.cloud.bootstrap.name:none").run(); RefreshScope scope = new RefreshScope(); scope.setApplicationContext(this.context); - EnvironmentTestUtils.addEnvironment(this.context, - "spring.cloud.bootstrap.sources=" - + ExternalPropertySourceLocator.class.getName()); + TestPropertyValues + .of("spring.cloud.bootstrap.sources=" + + ExternalPropertySourceLocator.class.getName()) + .applyTo(this.context); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection keys = endpoint.refresh(); @@ -112,16 +111,18 @@ public class RefreshEndpointTests { @Test public void springMainSourcesEmptyInRefreshCycle() throws Exception { - this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE) - .bannerMode(Mode.OFF).properties("spring.cloud.bootstrap.name:none") - .run(); + this.context = new SpringApplicationBuilder(Empty.class) + .web(WebApplicationType.NONE).bannerMode(Mode.OFF) + .properties("spring.cloud.bootstrap.name:none").run(); RefreshScope scope = new RefreshScope(); scope.setApplicationContext(this.context); // spring.main.sources should be empty when the refresh cycle starts (we don't // want any config files from the application context getting into the one used to // construct the environment for refresh) - EnvironmentTestUtils.addEnvironment(this.context, - "spring.main.sources=" + ExternalPropertySourceLocator.class.getName()); + TestPropertyValues + .of("spring.main.sources=" + + ExternalPropertySourceLocator.class.getName()) + .applyTo(this.context); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher); Collection keys = endpoint.refresh(); @@ -130,8 +131,8 @@ public class RefreshEndpointTests { @Test public void eventsPublishedInOrder() throws Exception { - this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE) - .bannerMode(Mode.OFF).run(); + this.context = new SpringApplicationBuilder(Empty.class) + .web(WebApplicationType.NONE).bannerMode(Mode.OFF).run(); RefreshScope scope = new RefreshScope(); scope.setApplicationContext(this.context); ContextRefresher contextRefresher = new ContextRefresher(this.context, scope); @@ -189,7 +190,7 @@ public class RefreshEndpointTests { @Override public PropertySource locate(Environment environment) { return new MapPropertySource("external", Collections - . singletonMap("external.message", "I'm External")); + .singletonMap("external.message", "I'm External")); } } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java index cb772bfb..35f5764c 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java @@ -15,6 +15,9 @@ */ package org.springframework.cloud.logging; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.Collections; import org.junit.After; @@ -23,13 +26,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggingSystem; -import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.core.env.StandardEnvironment; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - /** * @author Dave Syer * @@ -49,8 +49,8 @@ public class LoggingRebinderTests { public void logLevelsChanged() { assertFalse(this.logger.isTraceEnabled()); StandardEnvironment environment = new StandardEnvironment(); - EnvironmentTestUtils.addEnvironment(environment, - "logging.level.org.springframework.web=TRACE"); + TestPropertyValues.of("logging.level.org.springframework.web=TRACE") + .applyTo(environment); this.rebinder.setEnvironment(environment); this.rebinder.onApplicationEvent(new EnvironmentChangeEvent( Collections.singleton("logging.level.org.springframework.web"))); @@ -61,8 +61,8 @@ public class LoggingRebinderTests { public void logLevelsLowerCase() { assertFalse(this.logger.isTraceEnabled()); StandardEnvironment environment = new StandardEnvironment(); - EnvironmentTestUtils.addEnvironment(environment, - "logging.level.org.springframework.web=trace"); + TestPropertyValues.of("logging.level.org.springframework.web=trace") + .applyTo(environment); this.rebinder.setEnvironment(environment); this.rebinder.onApplicationEvent(new EnvironmentChangeEvent( Collections.singleton("logging.level.org.springframework.web")));