From 3882552b43bea8db18632187e1b0c78042fdf3a6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 12 Sep 2017 10:22:35 +0100 Subject: [PATCH] Polish --- .../web/ManagementContextFactory.java | 1 + .../CompositeReactiveHealthIndicator.java | 6 +- .../security/StaticResourceRequest.java | 12 +-- ...AbstractSessionAutoConfigurationTests.java | 3 +- ...essionAutoConfigurationHazelcastTests.java | 35 ++++---- .../SessionAutoConfigurationJdbcTests.java | 79 ++++++++++--------- .../SessionAutoConfigurationRedisTests.java | 15 ++-- .../SessionAutoConfigurationTests.java | 68 ++++++++-------- .../ValidationAutoConfigurationTests.java | 2 +- 9 files changed, 116 insertions(+), 105 deletions(-) diff --git a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/ManagementContextFactory.java b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/ManagementContextFactory.java index 7d4f67fd98..ec17a98724 100644 --- a/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/ManagementContextFactory.java +++ b/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/ManagementContextFactory.java @@ -26,6 +26,7 @@ import org.springframework.context.ConfigurableApplicationContext; * @author Andy Wilkinson * @since 2.0.0 */ +@FunctionalInterface public interface ManagementContextFactory { /** diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java index cc3cef3870..9a4a7dd605 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeReactiveHealthIndicator.java @@ -93,10 +93,8 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator @Override public Mono health() { return Flux.fromIterable(this.indicators.entrySet()) - .flatMap((entry) -> Mono.zip( - Mono.just(entry.getKey()), - entry.getValue().health().compose(this.timeoutCompose)) - ) + .flatMap((entry) -> Mono.zip(Mono.just(entry.getKey()), + entry.getValue().health().compose(this.timeoutCompose))) .collectMap(Tuple2::getT1, Tuple2::getT2) .map(this.healthAggregator::aggregate); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java index c77fa88928..cb59255019 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceRequest.java @@ -48,8 +48,8 @@ public final class StaticResourceRequest { /** * Returns a matcher that includes all commonly used {@link Location Locations}. The - * {@link StaticResourceRequestMatcher#excluding(Location, Location...) excluding} method - * can be used to remove specific locations if required. For example: + * {@link StaticResourceRequestMatcher#excluding(Location, Location...) excluding} + * method can be used to remove specific locations if required. For example: *
 	 * StaticResourceRequest.toCommonLocations().excluding(Location.CSS)
 	 * 
@@ -140,8 +140,8 @@ public final class StaticResourceRequest { } /** - * Return a new {@link StaticResourceRequestMatcher} based on this one but excluding the - * specified locations. + * Return a new {@link StaticResourceRequestMatcher} based on this one but + * excluding the specified locations. * @param first the first location to exclude * @param rest additional locations to exclude * @return a new {@link StaticResourceRequestMatcher} @@ -151,8 +151,8 @@ public final class StaticResourceRequest { } /** - * Return a new {@link StaticResourceRequestMatcher} based on this one but excluding the - * specified locations. + * Return a new {@link StaticResourceRequestMatcher} based on this one but + * excluding the specified locations. * @param locations the locations to exclude * @return a new {@link StaticResourceRequestMatcher} */ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java index 9ba806ba7b..a459696e16 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/AbstractSessionAutoConfigurationTests.java @@ -30,8 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; public abstract class AbstractSessionAutoConfigurationTests { protected > T validateSessionRepository( - AssertableWebApplicationContext context, - Class type) { + AssertableWebApplicationContext context, Class type) { assertThat(context).hasSingleBean(SessionRepository.class); SessionRepository repository = context.getBean(SessionRepository.class); assertThat(repository).as("Wrong session repository type").isInstanceOf(type); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java index 05475aee96..94449496e1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationHazelcastTests.java @@ -46,7 +46,6 @@ public class SessionAutoConfigurationHazelcastTests .withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class)) .withUserConfiguration(HazelcastConfiguration.class); - @Test public void defaultConfig() { this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast") @@ -60,25 +59,29 @@ public class SessionAutoConfigurationHazelcastTests @Test public void customMapName() { - this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast", - "spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> { - validateSessionRepository(context, HazelcastSessionRepository.class); - HazelcastInstance hazelcastInstance = context - .getBean(HazelcastInstance.class); - verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); - }); + this.contextRunner + .withPropertyValues("spring.session.store-type=hazelcast", + "spring.session.hazelcast.map-name=foo:bar:biz") + .run((context) -> { + validateSessionRepository(context, HazelcastSessionRepository.class); + HazelcastInstance hazelcastInstance = context + .getBean(HazelcastInstance.class); + verify(hazelcastInstance, times(1)).getMap("foo:bar:biz"); + }); } @Test public void customFlushMode() { - this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast", - "spring.session.hazelcast.flush-mode=immediate").run((context) -> { - HazelcastSessionRepository repository = validateSessionRepository(context, - HazelcastSessionRepository.class); - assertThat(new DirectFieldAccessor(repository) - .getPropertyValue("hazelcastFlushMode")) - .isEqualTo(HazelcastFlushMode.IMMEDIATE); - }); + this.contextRunner + .withPropertyValues("spring.session.store-type=hazelcast", + "spring.session.hazelcast.flush-mode=immediate") + .run((context) -> { + HazelcastSessionRepository repository = validateSessionRepository( + context, HazelcastSessionRepository.class); + assertThat(new DirectFieldAccessor(repository) + .getPropertyValue("hazelcastFlushMode")) + .isEqualTo(HazelcastFlushMode.IMMEDIATE); + }); } @Configuration diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java index a20f87b4aa..4a4a1edaf2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java @@ -54,60 +54,63 @@ public class SessionAutoConfigurationJdbcTests @Test public void defaultConfig() { - this.contextRunner.withConfiguration(AutoConfigurations.of( - JdbcTemplateAutoConfiguration.class)) + this.contextRunner + .withConfiguration( + AutoConfigurations.of(JdbcTemplateAutoConfiguration.class)) .withPropertyValues("spring.session.store-type=jdbc").run((context) -> { - JdbcOperationsSessionRepository repository = validateSessionRepository(context, - JdbcOperationsSessionRepository.class); - assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) - .isEqualTo("SPRING_SESSION"); - assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()) - .isEqualTo(DatabaseInitializationMode.EMBEDDED); - assertThat(context.getBean(JdbcOperations.class) - .queryForList("select * from SPRING_SESSION")).isEmpty(); - }); + JdbcOperationsSessionRepository repository = validateSessionRepository( + context, JdbcOperationsSessionRepository.class); + assertThat(new DirectFieldAccessor(repository) + .getPropertyValue("tableName")).isEqualTo("SPRING_SESSION"); + assertThat(context.getBean(JdbcSessionProperties.class) + .getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); + assertThat(context.getBean(JdbcOperations.class) + .queryForList("select * from SPRING_SESSION")).isEmpty(); + }); } @Test public void filterOrderCanBeCustomized() { this.contextRunner.withPropertyValues("spring.session.store-type=jdbc", - "spring.session.servlet.filter-order=123").run((context) -> { - FilterRegistrationBean registration = context - .getBean(FilterRegistrationBean.class); - assertThat(registration.getOrder()).isEqualTo(123); - }); + "spring.session.servlet.filter-order=123").run((context) -> { + FilterRegistrationBean registration = context + .getBean(FilterRegistrationBean.class); + assertThat(registration.getOrder()).isEqualTo(123); + }); } @Test public void disableDatabaseInitializer() { - this.contextRunner.withPropertyValues( - "spring.session.store-type=jdbc", + this.contextRunner.withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.initialize-schema=never").run((context) -> { - JdbcOperationsSessionRepository repository = validateSessionRepository(context, - JdbcOperationsSessionRepository.class); - assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) - .isEqualTo("SPRING_SESSION"); - assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()) - .isEqualTo(DatabaseInitializationMode.NEVER); - this.thrown.expect(BadSqlGrammarException.class); - context.getBean(JdbcOperations.class).queryForList( - "select * from SPRING_SESSION"); - }); + JdbcOperationsSessionRepository repository = validateSessionRepository( + context, JdbcOperationsSessionRepository.class); + assertThat(new DirectFieldAccessor(repository) + .getPropertyValue("tableName")).isEqualTo("SPRING_SESSION"); + assertThat(context.getBean(JdbcSessionProperties.class) + .getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.NEVER); + this.thrown.expect(BadSqlGrammarException.class); + context.getBean(JdbcOperations.class) + .queryForList("select * from SPRING_SESSION"); + }); } @Test public void customTableName() { - this.contextRunner.withPropertyValues( - "spring.session.store-type=jdbc", - "spring.session.jdbc.table-name=FOO_BAR", - "spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql") + this.contextRunner + .withPropertyValues("spring.session.store-type=jdbc", + "spring.session.jdbc.table-name=FOO_BAR", + "spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql") .run((context) -> { - JdbcOperationsSessionRepository repository = validateSessionRepository(context, - JdbcOperationsSessionRepository.class); - assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) - .isEqualTo("FOO_BAR"); - assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()) - .isEqualTo(DatabaseInitializationMode.EMBEDDED); + JdbcOperationsSessionRepository repository = validateSessionRepository( + context, JdbcOperationsSessionRepository.class); + assertThat(new DirectFieldAccessor(repository) + .getPropertyValue("tableName")).isEqualTo("FOO_BAR"); + assertThat(context.getBean(JdbcSessionProperties.class) + .getInitializeSchema()) + .isEqualTo(DatabaseInitializationMode.EMBEDDED); assertThat(context.getBean(JdbcOperations.class) .queryForList("select * from FOO_BAR")).isEmpty(); }); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java index ed8b907d7c..1b02a30d60 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java @@ -45,10 +45,10 @@ public class SessionAutoConfigurationRedisTests protected final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class)); - @Test public void redisSessionStore() { - this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)) + this.contextRunner + .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)) .withPropertyValues("spring.session.store-type=redis") .run(validateSpringSessionUsesRedis("spring:session:event:created:", RedisFlushMode.ON_SAVE)); @@ -56,7 +56,8 @@ public class SessionAutoConfigurationRedisTests @Test public void redisSessionStoreWithCustomizations() { - this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)) + this.contextRunner + .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class)) .withPropertyValues("spring.session.store-type=redis", "spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate") @@ -67,12 +68,12 @@ public class SessionAutoConfigurationRedisTests private ContextConsumer validateSpringSessionUsesRedis( String sessionCreatedChannelPrefix, RedisFlushMode flushMode) { return context -> { - RedisOperationsSessionRepository repository = validateSessionRepository(context, - RedisOperationsSessionRepository.class); + RedisOperationsSessionRepository repository = validateSessionRepository( + context, RedisOperationsSessionRepository.class); assertThat(repository.getSessionCreatedChannelPrefix()) .isEqualTo(sessionCreatedChannelPrefix); - assertThat(new DirectFieldAccessor(repository).getPropertyValue("redisFlushMode")) - .isEqualTo(flushMode); + assertThat(new DirectFieldAccessor(repository) + .getPropertyValue("redisFlushMode")).isEqualTo(flushMode); }; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java index a02b8025ea..2fb7db9d85 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java @@ -54,10 +54,10 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat public void contextFailsIfStoreTypeNotSet() { this.contextRunner.run((context) -> { assertThat(context).hasFailed(); - assertThat(context).getFailure().hasMessageContaining( - "No Spring Session store is configured"); - assertThat(context).getFailure().hasMessageContaining( - "set the 'spring.session.store-type' property"); + assertThat(context).getFailure() + .hasMessageContaining("No Spring Session store is configured"); + assertThat(context).getFailure() + .hasMessageContaining("set the 'spring.session.store-type' property"); }); } @@ -66,11 +66,12 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat this.contextRunner.withPropertyValues("spring.session.store-type=jdbc") .run((context) -> { assertThat(context).hasFailed(); - assertThat(context).getFailure().isInstanceOf(BeanCreationException.class); + assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class); assertThat(context).getFailure().hasMessageContaining( "No session repository could be auto-configured"); - assertThat(context).getFailure().hasMessageContaining( - "session store type is 'jdbc'"); + assertThat(context).getFailure() + .hasMessageContaining("session store type is 'jdbc'"); }); } @@ -85,35 +86,39 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat public void backOffIfSessionRepositoryIsPresent() { this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class) .withPropertyValues("spring.session.store-type=redis").run((context) -> { - MapSessionRepository repository = validateSessionRepository(context, - MapSessionRepository.class); - assertThat(context).getBean("mySessionRepository").isSameAs(repository); - }); + MapSessionRepository repository = validateSessionRepository(context, + MapSessionRepository.class); + assertThat(context).getBean("mySessionRepository") + .isSameAs(repository); + }); } @Test public void springSessionTimeoutIsNotAValidProperty() { - this.contextRunner.withPropertyValues( - "spring.session.timeout=3000").run((context) -> { - assertThat(context).hasFailed(); - assertThat(context).getFailure().isInstanceOf(BeanCreationException.class); - assertThat(context).getFailure().hasMessageContaining("Could not bind"); - }); + this.contextRunner.withPropertyValues("spring.session.timeout=3000") + .run((context) -> { + assertThat(context).hasFailed(); + assertThat(context).getFailure() + .isInstanceOf(BeanCreationException.class); + assertThat(context).getFailure() + .hasMessageContaining("Could not bind"); + }); } @SuppressWarnings("unchecked") @Test public void filterIsRegisteredWithAsyncErrorAndRequestDispatcherTypes() { - this.contextRunner.withUserConfiguration( - SessionRepositoryConfiguration.class).run((context) -> { - FilterRegistrationBean registration = context - .getBean(FilterRegistrationBean.class); - assertThat(registration.getFilter()) - .isSameAs(context.getBean(SessionRepositoryFilter.class)); - assertThat((EnumSet) ReflectionTestUtils.getField(registration, - "dispatcherTypes")).containsOnly(DispatcherType.ASYNC, - DispatcherType.ERROR, DispatcherType.REQUEST); - }); + this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class) + .run((context) -> { + FilterRegistrationBean registration = context + .getBean(FilterRegistrationBean.class); + assertThat(registration.getFilter()) + .isSameAs(context.getBean(SessionRepositoryFilter.class)); + assertThat((EnumSet) ReflectionTestUtils + .getField(registration, "dispatcherTypes")).containsOnly( + DispatcherType.ASYNC, DispatcherType.ERROR, + DispatcherType.REQUEST); + }); } @Test @@ -131,13 +136,14 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat @Test public void filterDispatcherTypesCanBeCustomized() { this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class) - .withPropertyValues("spring.session.servlet.filter-dispatcher-types=error, request") + .withPropertyValues( + "spring.session.servlet.filter-dispatcher-types=error, request") .run((context) -> { FilterRegistrationBean registration = context .getBean(FilterRegistrationBean.class); - assertThat((EnumSet) ReflectionTestUtils.getField(registration, - "dispatcherTypes")).containsOnly(DispatcherType.ERROR, - DispatcherType.REQUEST); + assertThat((EnumSet) ReflectionTestUtils + .getField(registration, "dispatcherTypes")).containsOnly( + DispatcherType.ERROR, DispatcherType.REQUEST); }); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java index ecf0ac4bbd..561bcc8cb8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfigurationTests.java @@ -368,7 +368,7 @@ public class ValidationAutoConfigurationTests { static class TestBeanPostProcessor implements BeanPostProcessor { - private Set postProcessed = new HashSet(); + private Set postProcessed = new HashSet<>(); @Override public Object postProcessAfterInitialization(Object bean, String name) {