From a841a6a11d9434f2513589a479004dc20bc2599e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 4 May 2017 11:40:57 -0700 Subject: [PATCH] Polish --- .../redis/RedisReactiveAutoConfiguration.java | 15 ++---- .../flyway/FlywayAutoConfiguration.java | 3 +- .../hazelcast/HazelcastClientFactory.java | 5 +- .../HazelcastConfigResourceCondition.java | 4 +- .../thymeleaf/ThymeleafAutoConfiguration.java | 6 +-- .../RedisAutoConfigurationJedisTests.java | 2 +- .../RedisReactiveAutoConfigurationTests.java | 4 +- ...HazelcastAutoConfigurationClientTests.java | 7 +-- .../diagnostics/AbstractFailureAnalyzer.java | 2 +- .../EmbeddedServerPortFileWriterTests.java | 53 +++++++++++-------- .../UndertowServletWebServerFactoryTests.java | 8 +-- 11 files changed, 54 insertions(+), 55 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.java index aa3c36aeb0..c9f486efe7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfiguration.java @@ -51,16 +51,11 @@ public class RedisReactiveAutoConfiguration { public ReactiveRedisTemplate reactiveRedisTemplate( ReactiveRedisConnectionFactory reactiveRedisConnectionFactory, ResourceLoader resourceLoader) { - - JdkSerializationRedisSerializer jdkSerializer = - new JdkSerializationRedisSerializer(resourceLoader.getClassLoader()); - - RedisSerializationContext serializationContext = - RedisSerializationContext.newSerializationContext() - .key(jdkSerializer) - .value(jdkSerializer) - .hashKey(jdkSerializer) - .hashValue(jdkSerializer).build(); + JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer( + resourceLoader.getClassLoader()); + RedisSerializationContext serializationContext = RedisSerializationContext + .newSerializationContext().key(jdkSerializer).value(jdkSerializer) + .hashKey(jdkSerializer).hashValue(jdkSerializer).build(); return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory, serializationContext); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 6a6ac055b8..291dec5ed0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -107,8 +107,7 @@ public class FlywayAutoConfiguration { this.dataSource = dataSource.getIfUnique(); this.flywayDataSource = flywayDataSource.getIfAvailable(); this.migrationStrategy = migrationStrategy.getIfAvailable(); - this.flywayCallbacks = flywayCallbacks - .getIfAvailable(Collections::emptyList); + this.flywayCallbacks = flywayCallbacks.getIfAvailable(Collections::emptyList); } @PostConstruct diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientFactory.java index 75efe28ed0..fbba28813f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientFactory.java @@ -56,7 +56,6 @@ public class HazelcastClientFactory { this.clientConfig = clientConfig; } - private ClientConfig getClientConfig(Resource clientConfigLocation) throws IOException { URL configUrl = clientConfigLocation.getURL(); @@ -69,8 +68,8 @@ public class HazelcastClientFactory { */ public HazelcastInstance getHazelcastInstance() { if (StringUtils.hasText(this.clientConfig.getInstanceName())) { - return HazelcastClient.getHazelcastClientByName( - this.clientConfig.getInstanceName()); + return HazelcastClient + .getHazelcastClientByName(this.clientConfig.getInstanceName()); } return HazelcastClient.newHazelcastClient(this.clientConfig); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java index 7de04e03c6..fd6e465489 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java @@ -48,8 +48,8 @@ public abstract class HazelcastConfigResourceCondition extends ResourceCondition protected ConditionOutcome getResourceOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { if (System.getProperty(this.configSystemProperty) != null) { - return ConditionOutcome.match(startConditionMessage() - .because("System property '" + this.configSystemProperty + "' is set.")); + return ConditionOutcome.match(startConditionMessage().because( + "System property '" + this.configSystemProperty + "' is set.")); } return super.getResourceOutcome(context, metadata); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index b3acc7b21d..22ebd40f93 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -137,8 +137,7 @@ public class ThymeleafAutoConfiguration { Collection templateResolvers, ObjectProvider> dialectsProvider) { this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider - .getIfAvailable(Collections::emptyList); + this.dialects = dialectsProvider.getIfAvailable(Collections::emptyList); } @Bean @@ -221,8 +220,7 @@ public class ThymeleafAutoConfiguration { ThymeleafReactiveConfiguration(Collection templateResolvers, ObjectProvider> dialectsProvider) { this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider - .getIfAvailable(Collections::emptyList); + this.dialects = dialectsProvider.getIfAvailable(Collections::emptyList); } @Bean diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index 182259abbd..ac1b887f9b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfigurationTests.java index 48c20081f1..c852e2746d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisReactiveAutoConfigurationTests.java @@ -46,12 +46,10 @@ public class RedisReactiveAutoConfigurationTests { @Test public void testDefaultRedisConfiguration() { load(); - Map beans = this.context.getBeansOfType( - ReactiveRedisTemplate.class); + Map beans = this.context.getBeansOfType(ReactiveRedisTemplate.class); assertThat(beans).containsOnlyKeys("reactiveRedisTemplate"); } - private void load(String... environment) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(ctx, environment); 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 03d0886c81..203266ea96 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 @@ -78,8 +78,8 @@ public class HazelcastAutoConfigurationClientTests { @Test public void systemProperty() throws IOException { System.setProperty(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, - "classpath:org/springframework/boot/autoconfigure/hazelcast/" + - "hazelcast-client-specific.xml"); + "classpath:org/springframework/boot/autoconfigure/hazelcast/" + + "hazelcast-client-specific.xml"); try { load(); HazelcastInstance hazelcastInstance = this.context @@ -120,7 +120,8 @@ public class HazelcastAutoConfigurationClientTests { @Test public void clientConfigTakesPrecedence() { - load(HazelcastServerAndClientConfig.class, "spring.hazelcast.config=this-is-ignored.xml"); + load(HazelcastServerAndClientConfig.class, + "spring.hazelcast.config=this-is-ignored.xml"); HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance).isInstanceOf(HazelcastClientProxy.class); diff --git a/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java b/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java index fd48cba9c2..0be953bfdb 100644 --- a/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java +++ b/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java index e94033800c..d9b818ee52 100644 --- a/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java @@ -19,6 +19,8 @@ package org.springframework.boot.system; import java.io.File; import java.io.FileReader; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; import java.util.function.BiFunction; @@ -59,28 +61,35 @@ public class EmbeddedServerPortFileWriterTests { @Parameters(name = "{0}") public static Object[] parameters() { - BiFunction servletEvent = ( - String name, Integer port) -> { - ServletWebServerApplicationContext applicationContext = mock( - ServletWebServerApplicationContext.class); - given(applicationContext.getNamespace()).willReturn(name); - WebServer source = mock(WebServer.class); - given(source.getPort()).willReturn(port); - ServletWebServerInitializedEvent event = new ServletWebServerInitializedEvent( - source, applicationContext); - return event; - }; - BiFunction reactiveEvent = ( - String name, Integer port) -> { - ReactiveWebServerApplicationContext applicationContext = mock( - ReactiveWebServerApplicationContext.class); - given(applicationContext.getNamespace()).willReturn(name); - WebServer source = mock(WebServer.class); - given(source.getPort()).willReturn(port); - return new ReactiveWebServerInitializedEvent(source, applicationContext); - }; - return new Object[] { new Object[] { "Servlet", servletEvent }, - new Object[] { "Reactive", reactiveEvent } }; + Map> parameters = new LinkedHashMap<>(); + parameters.put("Servlet", + EmbeddedServerPortFileWriterTests::servletEventParameter); + parameters.put("Reactive", + EmbeddedServerPortFileWriterTests::reactiveEventParameter); + return parameters.entrySet().stream() + .map((e) -> new Object[] { e.getKey(), e.getValue() }).toArray(); + } + + private static WebServerInitializedEvent servletEventParameter(String name, + Integer port) { + ServletWebServerApplicationContext applicationContext = mock( + ServletWebServerApplicationContext.class); + given(applicationContext.getNamespace()).willReturn(name); + WebServer source = mock(WebServer.class); + given(source.getPort()).willReturn(port); + ServletWebServerInitializedEvent event = new ServletWebServerInitializedEvent( + source, applicationContext); + return event; + } + + private static WebServerInitializedEvent reactiveEventParameter(String name, + Integer port) { + ReactiveWebServerApplicationContext applicationContext = mock( + ReactiveWebServerApplicationContext.class); + given(applicationContext.getNamespace()).willReturn(name); + WebServer source = mock(WebServer.class); + given(source.getPort()).willReturn(port); + return new ReactiveWebServerInitializedEvent(source, applicationContext); } private final BiFunction eventFactory; diff --git a/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java index 02f37f1499..de6fd7c85c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java @@ -261,11 +261,11 @@ public class UndertowServletWebServerFactoryTests } private ServletContainer getServletContainerFromNewFactory() { - UndertowServletWebServer container = (UndertowServletWebServer) - getFactory().getWebServer(); + UndertowServletWebServer container = (UndertowServletWebServer) getFactory() + .getWebServer(); try { - return ((DeploymentManager) ReflectionTestUtils.getField(container, "manager")) - .getDeployment().getServletContainer(); + return ((DeploymentManager) ReflectionTestUtils.getField(container, + "manager")).getDeployment().getServletContainer(); } finally { container.stop();