From d77c4c83a1f63eb5b771942f01134870c799878f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 9 May 2018 09:19:03 +0100 Subject: [PATCH] Polish --- .../rest/RestClientAutoConfiguration.java | 15 ++++++----- .../RestClientAutoConfigurationTests.java | 25 ++++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java index 39861f044a..3c17aaa61f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java @@ -39,8 +39,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * {@link EnableAutoConfiguration Auto-Configuration} - * for Elasticseach REST clients. + * {@link EnableAutoConfiguration Auto-Configuration} for Elasticseach REST clients. * * @author Brian Clozel * @since 2.1.0 @@ -50,7 +49,6 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(RestClientProperties.class) public class RestClientAutoConfiguration { - private final RestClientProperties properties; private final List builderCustomizers; @@ -58,7 +56,8 @@ public class RestClientAutoConfiguration { public RestClientAutoConfiguration(RestClientProperties properties, ObjectProvider> builderCustomizers) { this.properties = properties; - this.builderCustomizers = builderCustomizers.getIfAvailable(Collections::emptyList); + this.builderCustomizers = builderCustomizers + .getIfAvailable(Collections::emptyList); } @Bean(destroyMethod = "close") @@ -69,8 +68,8 @@ public class RestClientAutoConfiguration { } protected RestClientBuilder configureBuilder() { - HttpHost[] hosts = this.properties.getUris().stream() - .map(HttpHost::create).toArray(HttpHost[]::new); + HttpHost[] hosts = this.properties.getUris().stream().map(HttpHost::create) + .toArray(HttpHost[]::new); RestClientBuilder builder = RestClient.builder(hosts); PropertyMapper map = PropertyMapper.get(); map.from(this.properties::getUsername).whenHasText().to((username) -> { @@ -78,8 +77,8 @@ public class RestClientAutoConfiguration { Credentials credentials = new UsernamePasswordCredentials( this.properties.getUsername(), this.properties.getPassword()); credentialsProvider.setCredentials(AuthScope.ANY, credentials); - builder.setHttpClientConfigCallback(httpClientBuilder -> - httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); + builder.setHttpClientConfigCallback((httpClientBuilder) -> httpClientBuilder + .setDefaultCredentialsProvider(credentialsProvider)); }); this.builderCustomizers.forEach((customizer) -> customizer.customize(builder)); return builder; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java index db10850d52..e2bd0fed32 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.elasticsearch.rest; - import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -49,26 +48,21 @@ public class RestClientAutoConfigurationTests { @Test public void configureShouldCreateBothRestClientVariants() { - this.contextRunner.run((context) -> { - assertThat(context).hasSingleBean(RestClient.class) - .hasSingleBean(RestHighLevelClient.class); - }); + this.contextRunner + .run((context) -> assertThat(context).hasSingleBean(RestClient.class) + .hasSingleBean(RestHighLevelClient.class)); } @Test public void configureWhenCustomClientShouldBackOff() { - this.contextRunner - .withUserConfiguration(CustomRestClientConfiguration.class) - .run((context) -> { - assertThat(context).hasSingleBean(RestClient.class) - .hasBean("customRestClient"); - }); + this.contextRunner.withUserConfiguration(CustomRestClientConfiguration.class) + .run((context) -> assertThat(context).hasSingleBean(RestClient.class) + .hasBean("customRestClient")); } @Test public void configureWhenBuilderCustomizerShouldApply() { - this.contextRunner - .withUserConfiguration(BuilderCustomizerConfiguration.class) + this.contextRunner.withUserConfiguration(BuilderCustomizerConfiguration.class) .run((context) -> { assertThat(context).hasSingleBean(RestClient.class); RestClient restClient = context.getBean(RestClient.class); @@ -86,7 +80,8 @@ public class RestClientAutoConfigurationTests { .withPropertyValues("spring.elasticsearch.rest.uris=http://localhost:" + node.getHttpPort()) .run((context) -> { - RestHighLevelClient client = context.getBean(RestHighLevelClient.class); + RestHighLevelClient client = context + .getBean(RestHighLevelClient.class); Map source = new HashMap<>(); source.put("a", "alpha"); source.put("b", "bravo"); @@ -112,7 +107,7 @@ public class RestClientAutoConfigurationTests { @Bean public RestClientBuilderCustomizer myCustomizer() { - return builder -> builder.setMaxRetryTimeoutMillis(42); + return (builder) -> builder.setMaxRetryTimeoutMillis(42); } }