From abf39915e8a46904f638088610707f6f1d718880 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 4 Aug 2017 11:12:33 +0100 Subject: [PATCH] Polish --- ...HealthIndicatorAutoConfigurationTests.java | 10 +- .../client/WebClientCodecCustomizer.java | 8 +- .../cache/CacheAutoConfigurationTests.java | 108 ++++++++---------- ...HazelcastAutoConfigurationClientTests.java | 38 +++--- ...HazelcastAutoConfigurationServerTests.java | 8 +- .../DataSourceAutoConfigurationTests.java | 20 ++-- .../jms/JmsAutoConfigurationTests.java | 12 +- .../HttpHandlerAutoConfigurationTests.java | 4 +- .../WebServicesAutoConfigurationTests.java | 9 +- .../launchscript/SysVinitLaunchScriptIT.java | 7 +- .../WebTestClientContextCustomizer.java | 9 +- ...AbstractApplicationContextRunnerTests.java | 23 ++-- 12 files changed, 104 insertions(+), 152 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 3e91dc5fdae6..4379a9ca8bfd 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -417,12 +417,10 @@ public void notNeo4jHealthIndicator() throws Exception { private ContextConsumer hasSingleHealthIndicator( Class type) { - return (context) -> { - assertThat(context).getBeans(HealthIndicator.class).hasSize(1) - .hasValueSatisfying(new Condition<>( - (indicator) -> indicator.getClass().equals(type), - "Wrong indicator type")); - }; + return (context) -> assertThat(context).getBeans(HealthIndicator.class).hasSize(1) + .hasValueSatisfying( + new Condition<>((indicator) -> indicator.getClass().equals(type), + "Wrong indicator type")); } @Configuration diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientCodecCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientCodecCustomizer.java index f42d8efc21ee..16148074c954 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientCodecCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientCodecCustomizer.java @@ -40,10 +40,10 @@ public WebClientCodecCustomizer(List codecCustomizers) { @Override public void customize(WebClient.Builder webClientBuilder) { webClientBuilder - .exchangeStrategies(ExchangeStrategies.builder().codecs((codecs) -> { - this.codecCustomizers - .forEach((customizer) -> customizer.customize(codecs)); - }).build()); + .exchangeStrategies(ExchangeStrategies.builder() + .codecs((codecs) -> this.codecCustomizers + .forEach((customizer) -> customizer.customize(codecs))) + .build()); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index dc46c595465c..6ebd701d79a8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -105,38 +105,33 @@ public class CacheAutoConfigurationTests { @Test public void noEnableCaching() { - this.contextRunner.withUserConfiguration(EmptyConfiguration.class) - .run((context) -> { - assertThat(context).doesNotHaveBean(CacheManager.class); - }); + this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run( + (context) -> assertThat(context).doesNotHaveBean(CacheManager.class)); } @Test public void cacheManagerBackOff() { this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class) - .run((context) -> { - assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) - .getCacheNames()).containsOnly("custom1"); - }); + .run((context) -> assertThat( + getCacheManager(context, ConcurrentMapCacheManager.class) + .getCacheNames()).containsOnly("custom1")); } @Test public void cacheManagerFromSupportBackOff() { this.contextRunner .withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class) - .run((context) -> { - assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) - .getCacheNames()).containsOnly("custom1"); - }); + .run((context) -> assertThat( + getCacheManager(context, ConcurrentMapCacheManager.class) + .getCacheNames()).containsOnly("custom1")); } @Test public void cacheResolverFromSupportBackOff() throws Exception { this.contextRunner .withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class) - .run((context) -> { - assertThat(context).doesNotHaveBean(CacheManager.class); - }); + .run((context) -> assertThat(context) + .doesNotHaveBean(CacheManager.class)); } @Test @@ -151,21 +146,19 @@ public void customCacheResolverCanBeDefined() throws Exception { @Test public void notSupportedCachingMode() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) - .withPropertyValues("spring.cache.type=foobar").run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining( - "Failed to bind properties under 'spring.cache.type'"); - }); + .withPropertyValues("spring.cache.type=foobar") + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class).hasMessageContaining( + "Failed to bind properties under 'spring.cache.type'")); } @Test public void simpleCacheExplicit() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) - .withPropertyValues("spring.cache.type=simple").run((context) -> { - assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) - .getCacheNames()).isEmpty(); - }); + .withPropertyValues("spring.cache.type=simple") + .run((context) -> assertThat( + getCacheManager(context, ConcurrentMapCacheManager.class) + .getCacheNames()).isEmpty()); } @Test @@ -206,13 +199,11 @@ public void genericCacheWithCaches() { @Test public void genericCacheExplicit() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) - .withPropertyValues("spring.cache.type=generic").run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining( - "No cache manager could be auto-configured") - .hasMessageContaining("GENERIC"); - }); + .withPropertyValues("spring.cache.type=generic") + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("No cache manager could be auto-configured") + .hasMessageContaining("GENERIC")); } @Test @@ -339,13 +330,11 @@ public void noOpCacheExplicit() { @Test public void jCacheCacheNoProviderExplicit() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) - .withPropertyValues("spring.cache.type=jcache").run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining( - "No cache manager could be auto-configured") - .hasMessageContaining("JCACHE"); - }); + .withPropertyValues("spring.cache.type=jcache") + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("No cache manager could be auto-configured") + .hasMessageContaining("JCACHE")); } @Test @@ -416,11 +405,9 @@ public void jCacheCacheWithUnknownProvider() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) .withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + wrongCachingProviderClassName) - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining(wrongCachingProviderClassName); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining(wrongCachingProviderClassName)); } @Test @@ -448,12 +435,10 @@ public void jCacheCacheWithWrongConfig() { .withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation) - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining("does not exist") - .hasMessageContaining(configLocation); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("does not exist") + .hasMessageContaining(configLocation)); } @Test @@ -692,10 +677,9 @@ public void infinispanCacheWithCaches() { .withPropertyValues("spring.cache.type=infinispan", "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar") - .run((context) -> { - assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class) - .getCacheNames()).containsOnly("foo", "bar"); - }); + .run((context) -> assertThat( + getCacheManager(context, SpringEmbeddedCacheManager.class) + .getCacheNames()).containsOnly("foo", "bar")); } @Test @@ -719,10 +703,9 @@ public void infinispanAsJCacheWithCaches() { "spring.cache.jcache.provider=" + cachingProviderClassName, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar") - .run((context) -> { - assertThat(getCacheManager(context, JCacheCacheManager.class) - .getCacheNames()).containsOnly("foo", "bar"); - }); + .run((context) -> assertThat( + getCacheManager(context, JCacheCacheManager.class) + .getCacheNames()).containsOnly("foo", "bar")); } @Test @@ -751,11 +734,10 @@ public void jCacheCacheWithCachesAndCustomizer() { "spring.cache.jcache.provider=" + cachingProviderClassName, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar") - .run((context) -> { - // see customizer - assertThat(getCacheManager(context, JCacheCacheManager.class) - .getCacheNames()).containsOnly("foo", "custom1"); - }); + .run((context) -> + // see customizer + assertThat(getCacheManager(context, JCacheCacheManager.class) + .getCacheNames()).containsOnly("foo", "custom1")); } finally { Caching.getCachingProvider(cachingProviderClassName).close(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java index 9d0b62f09186..7de3c902ec9e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java @@ -70,11 +70,9 @@ public void systemProperty() throws IOException { .withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY + "=classpath:org/springframework/boot/autoconfigure/hazelcast/" + "hazelcast-client-specific.xml") - .run((context) -> { - assertThat(context).getBean(HazelcastInstance.class) - .isInstanceOf(HazelcastInstance.class) - .has(nameStartingWith("hz.client_")); - }); + .run((context) -> assertThat(context).getBean(HazelcastInstance.class) + .isInstanceOf(HazelcastInstance.class) + .has(nameStartingWith("hz.client_"))); } @Test @@ -83,11 +81,9 @@ public void explicitConfigFile() throws IOException { .withPropertyValues( "spring.hazelcast.config=org/springframework/boot/autoconfigure/" + "hazelcast/hazelcast-client-specific.xml") - .run((context) -> { - assertThat(context).getBean(HazelcastInstance.class) - .isInstanceOf(HazelcastClientProxy.class) - .has(nameStartingWith("hz.client_")); - }); + .run((context) -> assertThat(context).getBean(HazelcastInstance.class) + .isInstanceOf(HazelcastClientProxy.class) + .has(nameStartingWith("hz.client_"))); } @Test @@ -95,32 +91,26 @@ public void explicitConfigUrl() throws IOException { this.contextRunner .withPropertyValues( "spring.hazelcast.config=hazelcast-client-default.xml") - .run((context) -> { - assertThat(context).getBean(HazelcastInstance.class) - .isInstanceOf(HazelcastClientProxy.class) - .has(nameStartingWith("hz.client_")); - }); + .run((context) -> assertThat(context).getBean(HazelcastInstance.class) + .isInstanceOf(HazelcastClientProxy.class) + .has(nameStartingWith("hz.client_"))); } @Test public void unknownConfigFile() { this.contextRunner .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining("foo/bar/unknown.xml"); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("foo/bar/unknown.xml")); } @Test public void clientConfigTakesPrecedence() { this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class) .withPropertyValues("spring.hazelcast.config=this-is-ignored.xml") - .run((context) -> { - assertThat(context).getBean(HazelcastInstance.class) - .isInstanceOf(HazelcastClientProxy.class); - }); + .run((context) -> assertThat(context).getBean(HazelcastInstance.class) + .isInstanceOf(HazelcastClientProxy.class)); } private Condition nameStartingWith(String prefix) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java index 6ed7efea40b5..a793f79ee1b6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java @@ -99,11 +99,9 @@ public void explicitConfigUrl() throws IOException { public void unknownConfigFile() { this.contextRunner .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining("foo/bar/unknown.xml"); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("foo/bar/unknown.xml")); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index 980701425f1e..356ce186fa27 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -85,10 +85,8 @@ public void testBadUrl() throws Exception { EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE; this.contextRunner .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class)); } finally { EmbeddedDatabaseConnection.override = null; @@ -100,11 +98,9 @@ public void testBadDriverClass() throws Exception { this.contextRunner .withPropertyValues( "spring.datasource.driverClassName:org.none.jdbcDriver") - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining("org.none.jdbcDriver"); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class) + .hasMessageContaining("org.none.jdbcDriver")); } @Test @@ -217,10 +213,8 @@ public void testExplicitDriverClassClearsUsername() throws Exception { @Test public void testDefaultDataSourceCanBeOverridden() throws Exception { this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class) - .run((context) -> { - assertThat(context).getBean(DataSource.class) - .isInstanceOf(BasicDataSource.class); - }); + .run((context) -> assertThat(context).getBean(DataSource.class) + .isInstanceOf(BasicDataSource.class)); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index 4b21f58ed56c..0dca3a93b935 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -414,13 +414,11 @@ public void testActiveMQOverriddenPoolAndRemoteServer() { @Test public void enableJmsAutomatically() throws Exception { this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class) - .run((context) -> { - assertThat(context) - .hasBean( - JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME) - .hasBean( - JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME); - }); + .run((context) -> assertThat(context) + .hasBean( + JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME) + .hasBean( + JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME)); } @Configuration diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java index b00998a840ae..3453241d8c1e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java @@ -56,9 +56,7 @@ public void shouldNotProcessIfExistingHttpHandler() { public void shouldConfigureHttpHandlerAnnotation() { this.contextRunner .withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class)) - .run((context) -> { - assertThat(context).hasSingleBean(HttpHandler.class); - }); + .run((context) -> assertThat(context).hasSingleBean(HttpHandler.class)); } @Configuration diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java index 6eb93e150e63..07eeef3d78fb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java @@ -55,12 +55,9 @@ public void defaultConfiguration() { @Test public void customPathMustBeginWithASlash() { this.contextRunner.withPropertyValues("spring.webservices.path=invalid") - .run((context) -> { - assertThat(context).getFailure() - .isInstanceOf(BeanCreationException.class) - .hasMessageContaining( - "Failed to bind properties under 'spring.webservices'"); - }); + .run((context) -> assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class).hasMessageContaining( + "Failed to bind properties under 'spring.webservices'")); } @Test diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index 812257651b23..5f17163e6791 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -446,10 +446,9 @@ private static final class SpringBootDockerCmdExecFactory extends DockerCmdExecFactoryImpl { private SpringBootDockerCmdExecFactory() { - withClientRequestFilters((requestContext) -> { - // Workaround for https://go-review.googlesource.com/#/c/3821/ - requestContext.getHeaders().add("Connection", "close"); - }); + withClientRequestFilters((requestContext) -> + // Workaround for https://go-review.googlesource.com/#/c/3821/ + requestContext.getHeaders().add("Connection", "close")); } private CopyToContainerCmdExec createCopyToContainerCmdExec() { diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java index 081c28acecf6..68dcc2fe74ff 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java @@ -138,11 +138,10 @@ private void customizeWebTestClientCodecs(WebTestClient.Builder clientBuilder, Collection codecCustomizers = context .getBeansOfType(CodecCustomizer.class).values(); if (!CollectionUtils.isEmpty(codecCustomizers)) { - clientBuilder.exchangeStrategies( - ExchangeStrategies.builder().codecs((codecs) -> { - codecCustomizers.forEach((codecCustomizer) -> codecCustomizer - .customize(codecs)); - }).build()); + clientBuilder.exchangeStrategies(ExchangeStrategies.builder() + .codecs((codecs) -> codecCustomizers.forEach( + (codecCustomizer) -> codecCustomizer.customize(codecs))) + .build()); } } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java index 1e1d29bb7f54..e4a42a57db69 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java @@ -54,9 +54,9 @@ public abstract class AbstractApplicationContextRunnerTests { - assertThat(System.getProperties()).containsEntry(key, "value"); - }); + get().withSystemProperties(key + "=value") + .run((context) -> assertThat(System.getProperties()).containsEntry(key, + "value")); assertThat(System.getProperties().containsKey(key)).isFalse(); } @@ -66,9 +66,8 @@ public void runWithSystemPropertiesWhenContextFailsShouldRemoveProperties() String key = "test." + UUID.randomUUID().toString(); assertThat(System.getProperties().containsKey(key)).isFalse(); get().withSystemProperties(key + "=value") - .withUserConfiguration(FailingConfig.class).run((context) -> { - assertThat(context).hasFailed(); - }); + .withUserConfiguration(FailingConfig.class) + .run((context) -> assertThat(context).hasFailed()); assertThat(System.getProperties().containsKey(key)).isFalse(); } @@ -79,9 +78,9 @@ public void runWithSystemPropertiesShouldRestoreOriginalProperties() System.setProperty(key, "value"); try { assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); - get().withSystemProperties(key + "=newValue").run((context) -> { - assertThat(System.getProperties()).containsEntry(key, "newValue"); - }); + get().withSystemProperties(key + "=newValue") + .run((context) -> assertThat(System.getProperties()) + .containsEntry(key, "newValue")); assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); } finally { @@ -96,9 +95,9 @@ public void runWithSystemPropertiesWhenValueIsNullShouldRemoveProperty() System.setProperty(key, "value"); try { assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); - get().withSystemProperties(key + "=").run((context) -> { - assertThat(System.getProperties()).doesNotContainKey(key); - }); + get().withSystemProperties(key + "=") + .run((context) -> assertThat(System.getProperties()) + .doesNotContainKey(key)); assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); } finally {