diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java index f1e6f2abcd..015496acdc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfiguration.java @@ -58,8 +58,8 @@ public class JmxMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean - public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { - return new JmxMeterRegistry(config, clock); + public JmxMeterRegistry jmxMeterRegistry(JmxConfig jmxConfig, Clock clock) { + return new JmxMeterRegistry(jmxConfig, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java index d724fe1159..97c54a7362 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java @@ -59,9 +59,9 @@ public class NewRelicMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean - public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig config, + public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig newRelicConfig, Clock clock) { - return new NewRelicMeterRegistry(config, clock); + return new NewRelicMeterRegistry(newRelicConfig, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java index 1e3062e851..e127c40e97 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfiguration.java @@ -58,9 +58,9 @@ public class WavefrontMetricsExportAutoConfiguration { @Bean @ConditionalOnMissingBean - public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, + public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig wavefrontConfig, Clock clock) { - return new WavefrontMeterRegistry(config, clock); + return new WavefrontMeterRegistry(wavefrontConfig, clock); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java index b75118f90e..f887def9e7 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java @@ -57,11 +57,12 @@ public class GraphiteMetricsExportAutoConfigurationTests { @Test public void autoConfiguresUseTagsAsPrefix() { this.contextRunner.withUserConfiguration(BaseConfiguration.class) - .withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app") + .withPropertyValues( + "management.metrics.export.graphite.tags-as-prefix=app") .run((context) -> { assertThat(context).hasSingleBean(GraphiteMeterRegistry.class); - GraphiteMeterRegistry registry = context.getBean( - GraphiteMeterRegistry.class); + GraphiteMeterRegistry registry = context + .getBean(GraphiteMeterRegistry.class); registry.counter("test.count", Tags.of("app", "myapp")); assertThat(registry.getDropwizardRegistry().getMeters()) .containsOnlyKeys("myapp.testCount"); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java index b44c938ce7..f971d89183 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxMetricsExportAutoConfigurationTests.java @@ -126,7 +126,7 @@ public class JmxMetricsExportAutoConfigurationTests { @Bean public JmxConfig customConfig() { - return k -> null; + return (key) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java index fd6ed0b3e2..6a210f1f5a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java @@ -128,7 +128,7 @@ public class StatsdMetricsExportAutoConfigurationTests { @Bean public StatsdConfig customConfig() { - return k -> null; + return (key) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationTests.java index 8006968762..28d79548f3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationTests.java @@ -39,14 +39,14 @@ public class WebMvcEndpointChildContextConfigurationTests { public void contextShouldConfigureRequestContextFilter() { this.contextRunner .withUserConfiguration(WebMvcEndpointChildContextConfiguration.class) - .run(context -> assertThat(context).hasSingleBean(OrderedRequestContextFilter.class)); + .run((context) -> assertThat(context) + .hasSingleBean(OrderedRequestContextFilter.class)); } @Test public void contextShouldNotConfigureRequestContextFilterWhenPresent() { - this.contextRunner - .withUserConfiguration(ExistingConfig.class, WebMvcEndpointChildContextConfiguration.class) - .run(context -> { + this.contextRunner.withUserConfiguration(ExistingConfig.class, + WebMvcEndpointChildContextConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(RequestContextFilter.class); assertThat(context).hasBean("testRequestContextFilter"); }); @@ -54,12 +54,11 @@ public class WebMvcEndpointChildContextConfigurationTests { @Test public void contextShouldNotConfigureRequestContextFilterWhenRequestContextListenerPresent() { - this.contextRunner - .withUserConfiguration(RequestContextListenerConfig.class, - WebMvcEndpointChildContextConfiguration.class) - .run(context -> { + this.contextRunner.withUserConfiguration(RequestContextListenerConfig.class, + WebMvcEndpointChildContextConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(RequestContextListener.class); - assertThat(context).doesNotHaveBean(OrderedRequestContextFilter.class); + assertThat(context) + .doesNotHaveBean(OrderedRequestContextFilter.class); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java index df807f919c..5590da26f3 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -74,19 +74,17 @@ public final class WebFluxTags { */ public static Tag uri(ServerWebExchange exchange) { if (exchange != null) { - PathPattern pathPattern = exchange.getAttribute( - HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); + PathPattern pathPattern = exchange + .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pathPattern != null) { return Tag.of("uri", pathPattern.getPatternString()); } - else { - HttpStatus status = exchange.getResponse().getStatusCode(); - if (status != null && status.is3xxRedirection()) { - return URI_REDIRECTION; - } - if (status != null && status.equals(HttpStatus.NOT_FOUND)) { - return URI_NOT_FOUND; - } + HttpStatus status = exchange.getResponse().getStatusCode(); + if (status != null && status.is3xxRedirection()) { + return URI_REDIRECTION; + } + if (status != null && status.equals(HttpStatus.NOT_FOUND)) { + return URI_NOT_FOUND; } String path = exchange.getRequest().getPath().value(); return Tag.of("uri", path.isEmpty() ? "root" : path); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java index bd910bc60f..3ac3b54e16 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java @@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link WebFluxTags}. + * * @author Brian Clozel */ public class WebFluxTagsTests { @@ -40,14 +41,13 @@ public class WebFluxTagsTests { @Before public void setup() { - this.exchange = MockServerWebExchange - .from(MockServerHttpRequest.get("")); + this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("")); } @Test public void uriTagValueIsBestMatchingPatternWhenAvailable() { - this.exchange.getAttributes().put( - HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse("/spring")); + this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, + this.parser.parse("/spring")); this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY); Tag tag = WebFluxTags.uri(this.exchange); assertThat(tag.getValue()).isEqualTo("/spring"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java index a4cc198552..78995ce94c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportMessage.java @@ -137,14 +137,15 @@ public class ConditionEvaluationReportMessage { private Map orderByName( Map outcomes) { - MultiValueMap map = mapShortNameToFullyQualifiedNames(outcomes.keySet()); + MultiValueMap map = mapToFullyQualifiedNames(outcomes.keySet()); List shortNames = new ArrayList<>(map.keySet()); Collections.sort(shortNames); Map result = new LinkedHashMap<>(); for (String shortName : shortNames) { List fullyQualifiedNames = map.get(shortName); if (fullyQualifiedNames.size() > 1) { - fullyQualifiedNames.forEach(k -> result.put(k, outcomes.get(k))); + fullyQualifiedNames.forEach((fullyQualifiedName) -> result + .put(fullyQualifiedName, outcomes.get(fullyQualifiedName))); } else { result.put(shortName, outcomes.get(fullyQualifiedNames.get(0))); @@ -153,9 +154,10 @@ public class ConditionEvaluationReportMessage { return result; } - private MultiValueMap mapShortNameToFullyQualifiedNames(Set keySet) { + private MultiValueMap mapToFullyQualifiedNames(Set keySet) { LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - keySet.forEach(k -> map.add(ClassUtils.getShortName(k), k)); + keySet.forEach((fullyQualifiedName) -> map + .add(ClassUtils.getShortName(fullyQualifiedName), fullyQualifiedName)); return map; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java index dee8ab911b..e3b899b663 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java index a8352d88a1..54b1e3416e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -131,16 +131,13 @@ public class ConditionEvaluationReportTests { .getConditionAndOutcomesBySource(); assertThat(map.size()).isEqualTo(2); Iterator iterator = map.get("a").iterator(); - ConditionAndOutcome conditionAndOutcome = iterator.next(); assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition1); assertThat(conditionAndOutcome.getOutcome()).isEqualTo(this.outcome1); - conditionAndOutcome = iterator.next(); assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition2); assertThat(conditionAndOutcome.getOutcome()).isEqualTo(this.outcome2); assertThat(iterator.hasNext()).isFalse(); - iterator = map.get("b").iterator(); conditionAndOutcome = iterator.next(); assertThat(conditionAndOutcome.getCondition()).isEqualTo(this.condition3); @@ -187,16 +184,13 @@ public class ConditionEvaluationReportTests { new ConditionOutcome(true, "Message 2")); ConditionAndOutcome outcome3 = new ConditionAndOutcome(this.condition3, new ConditionOutcome(true, "Message 2")); - assertThat(outcome1).isEqualTo(outcome1); assertThat(outcome1).isNotEqualTo(outcome2); assertThat(outcome2).isEqualTo(outcome3); - ConditionAndOutcomes outcomes = new ConditionAndOutcomes(); outcomes.add(this.condition1, new ConditionOutcome(true, "Message 1")); outcomes.add(this.condition2, new ConditionOutcome(true, "Message 2")); outcomes.add(this.condition3, new ConditionOutcome(true, "Message 2")); - assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2); } @@ -207,12 +201,10 @@ public class ConditionEvaluationReportTests { ConditionEvaluationReport report = ConditionEvaluationReport .get(context.getBeanFactory()); String autoconfigKey = MultipartAutoConfiguration.class.getName(); - ConditionAndOutcomes outcomes = report.getConditionAndOutcomesBySource() .get(autoconfigKey); assertThat(outcomes).isNotEqualTo(nullValue()); assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2); - List messages = new ArrayList<>(); for (ConditionAndOutcome outcome : outcomes) { messages.add(outcome.getOutcome().getMessage()); @@ -251,10 +243,11 @@ public class ConditionEvaluationReportTests { context.refresh(); ConditionEvaluationReport report = ConditionEvaluationReport .get(context.getBeanFactory()); - assertThat(report.getConditionAndOutcomesBySource()) - .containsKeys("org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration", - "org.springframework.boot.autoconfigure.condition.config.first.SampleAutoConfiguration", - "org.springframework.boot.autoconfigure.condition.config.second.SampleAutoConfiguration"); + assertThat(report.getConditionAndOutcomesBySource()).containsKeys( + "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration", + "org.springframework.boot.autoconfigure.condition.config.first.SampleAutoConfiguration", + "org.springframework.boot.autoconfigure.condition.config.second.SampleAutoConfiguration"); + context.close(); } @Test @@ -267,10 +260,12 @@ public class ConditionEvaluationReportTests { ConditionEvaluationReport report = ConditionEvaluationReport .get(context.getBeanFactory()); String reportMessage = new ConditionEvaluationReportMessage(report).toString(); - assertThat(reportMessage) - .contains("WebMvcAutoConfiguration", "org.springframework.boot.autoconfigure.condition.config.first.SampleAutoConfiguration", - "org.springframework.boot.autoconfigure.condition.config.second.SampleAutoConfiguration"); - assertThat(reportMessage).doesNotContain("org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration"); + assertThat(reportMessage).contains("WebMvcAutoConfiguration", + "org.springframework.boot.autoconfigure.condition.config.first.SampleAutoConfiguration", + "org.springframework.boot.autoconfigure.condition.config.second.SampleAutoConfiguration"); + assertThat(reportMessage).doesNotContain( + "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration"); + context.close(); } private int getNumberOfOutcomes(ConditionAndOutcomes outcomes) { @@ -296,12 +291,12 @@ public class ConditionEvaluationReportTests { } @Configuration - @Conditional({ConditionEvaluationReportTests.MatchParseCondition.class, - ConditionEvaluationReportTests.NoMatchBeanCondition.class}) + @Conditional({ ConditionEvaluationReportTests.MatchParseCondition.class, + ConditionEvaluationReportTests.NoMatchBeanCondition.class }) public static class NegativeOuterConfig { @Configuration - @Conditional({ConditionEvaluationReportTests.MatchParseCondition.class}) + @Conditional({ ConditionEvaluationReportTests.MatchParseCondition.class }) public static class PositiveInnerConfig { @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/config/first/SampleAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/config/first/SampleAutoConfiguration.java index 778c2403ed..ae7112f4ba 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/config/first/SampleAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/config/first/SampleAutoConfiguration.java @@ -36,4 +36,3 @@ public class SampleAutoConfiguration { } } - diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java index 0cfe72df71..8d1029d995 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebTestClientAutoConfigurationTests.java @@ -46,8 +46,8 @@ import static org.mockito.Mockito.verify; public class WebTestClientAutoConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of( - WebTestClientAutoConfiguration.class)); + .withConfiguration( + AutoConfigurations.of(WebTestClientAutoConfiguration.class)); @Test public void shouldNotBeConfiguredWithoutWebHandler() { @@ -63,8 +63,8 @@ public class WebTestClientAutoConfigurationTests { .run((context) -> { assertThat(context).hasSingleBean(WebTestClient.class); assertThat(context).hasSingleBean(CodecCustomizer.class); - verify(context.getBean(CodecCustomizer.class)).customize( - any(CodecConfigurer.class)); + verify(context.getBean(CodecCustomizer.class)) + .customize(any(CodecConfigurer.class)); }); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java index 6c095a6bfa..9b1a120632 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -212,8 +212,8 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { } /** - * {@link PropertyMapper} that delegates to other {@link PropertyMapper}s. - * It also swallows exceptions when the mapping fails. + * {@link PropertyMapper} that delegates to other {@link PropertyMapper}s and also + * swallows exceptions when the mapping fails. */ private static class DelegatingPropertyMapper implements PropertyMapper { @@ -226,27 +226,22 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { @Override public PropertyMapping[] map( ConfigurationPropertyName configurationPropertyName) { - List mappings = new ArrayList<>(); - for (PropertyMapper mapper : this.mappers) { - try { - mappings.addAll(Arrays.asList(mapper.map(configurationPropertyName))); - } - catch (Exception ex) { - - } - } - return mappings.toArray(new PropertyMapping[] {}); + return callMappers((mapper) -> mapper.map(configurationPropertyName)); } @Override public PropertyMapping[] map(String propertySourceName) { + return callMappers((mapper) -> mapper.map(propertySourceName)); + } + + private PropertyMapping[] callMappers( + Function function) { List mappings = new ArrayList<>(); for (PropertyMapper mapper : this.mappers) { try { - mappings.addAll(Arrays.asList(mapper.map(propertySourceName))); + mappings.addAll(Arrays.asList(function.apply(mapper))); } catch (Exception ex) { - } } return mappings.toArray(new PropertyMapping[] {}); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java index a4b8bf9e45..fbd62f6313 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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-project/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java index 2347c3df69..3905a63e2c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java index ba8bd308b4..8d84227cb4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/ErrorPageFilterTests.java @@ -20,11 +20,13 @@ import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; @@ -65,7 +67,8 @@ public class ErrorPageFilterTests { private MockHttpServletResponse response = new MockHttpServletResponse(); - private MockFilterChain chain = new MockFilterChain(); + private MockFilterChain chain = new TestFilterChain((request, response, chain) -> { + }); @Rule public OutputCapture output = new OutputCapture(); @@ -82,15 +85,11 @@ public class ErrorPageFilterTests { @Test public void notAnErrorButNotOK() throws Exception { - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).setStatus(201); - super.doFilter(request, response); - response.flushBuffer(); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + response.setStatus(201); + chain.call(); + response.flushBuffer(); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponse) this.chain.getResponse()).getStatus()) .isEqualTo(201); @@ -102,14 +101,8 @@ public class ErrorPageFilterTests { @Test public void unauthorizedWithErrorPath() throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(401, "UNAUTHORIZED"); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain( + (request, response, chain) -> response.sendError(401, "UNAUTHORIZED")); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) this.chain @@ -126,14 +119,8 @@ public class ErrorPageFilterTests { public void responseCommitted() throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); this.response.setCommitted(true); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain( + (request, response, chain) -> response.sendError(400, "BAD")); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -146,14 +133,8 @@ public class ErrorPageFilterTests { @Test public void responseUncommittedWithoutErrorPage() throws Exception { - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain( + (request, response, chain) -> response.sendError(400, "BAD")); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -166,15 +147,10 @@ public class ErrorPageFilterTests { @Test public void oncePerRequest() throws Exception { - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull(); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + response.sendError(400, "BAD"); + assertThat(request.getAttribute("FILTER.FILTERED")).isNotNull(); + }); this.filter.init(new MockFilterConfig("FILTER")); this.filter.doFilter(this.request, this.response, this.chain); } @@ -182,14 +158,8 @@ public class ErrorPageFilterTests { @Test public void globalError() throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain( + (request, response, chain) -> response.sendError(400, "BAD")); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(400); @@ -206,14 +176,8 @@ public class ErrorPageFilterTests { @Test public void statusError() throws Exception { this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain( + (request, response, chain) -> response.sendError(400, "BAD")); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(400); @@ -230,15 +194,10 @@ public class ErrorPageFilterTests { @Test public void statusErrorWithCommittedResponse() throws Exception { this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400, "BAD"); - response.flushBuffer(); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + response.sendError(400, "BAD"); + response.flushBuffer(); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(400); @@ -249,14 +208,10 @@ public class ErrorPageFilterTests { @Test public void exceptionError() throws Exception { this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new RuntimeException("BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new RuntimeException("BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(500); @@ -281,29 +236,20 @@ public class ErrorPageFilterTests { @Test public void exceptionErrorWithCommittedResponse() throws Exception { this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - response.flushBuffer(); - throw new RuntimeException("BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + response.flushBuffer(); + throw new RuntimeException("BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.response.getForwardedUrl()).isNull(); } @Test public void statusCode() throws Exception { - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - assertThat(((HttpServletResponse) response).getStatus()).isEqualTo(200); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + assertThat(response.getStatus()).isEqualTo(200); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(200); @@ -312,14 +258,10 @@ public class ErrorPageFilterTests { @Test public void subClassExceptionError() throws Exception { this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new IllegalStateException("BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new IllegalStateException("BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(500); @@ -355,14 +297,10 @@ public class ErrorPageFilterTests { throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); this.request.setAsyncStarted(true); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new RuntimeException("BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new RuntimeException("BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -375,14 +313,10 @@ public class ErrorPageFilterTests { throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); this.request.setAsyncStarted(true); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - ((HttpServletResponse) response).sendError(400, "BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + response.sendError(400, "BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -405,14 +339,10 @@ public class ErrorPageFilterTests { throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); setUpAsyncDispatch(); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new RuntimeException("BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new RuntimeException("BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -425,14 +355,10 @@ public class ErrorPageFilterTests { throws Exception { this.filter.addErrorPages(new ErrorPage("/error")); setUpAsyncDispatch(); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - ((HttpServletResponse) response).sendError(400, "BAD"); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + response.sendError(400, "BAD"); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.chain.getRequest()).isEqualTo(this.request); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()) @@ -455,16 +381,10 @@ public class ErrorPageFilterTests { throws IOException, ServletException { this.request.setServletPath("/test"); this.filter.addErrorPages(new ErrorPage("/error")); - this.chain = new MockFilterChain() { - - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new RuntimeException(); - } - - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new RuntimeException(); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.output.toString()).contains("request [/test]"); } @@ -475,16 +395,10 @@ public class ErrorPageFilterTests { this.request.setServletPath("/test"); this.request.setPathInfo("/alpha"); this.filter.addErrorPages(new ErrorPage("/error")); - this.chain = new MockFilterChain() { - - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new RuntimeException(); - } - - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new RuntimeException(); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.output.toString()).contains("request [/test/alpha]"); } @@ -492,14 +406,10 @@ public class ErrorPageFilterTests { @Test public void nestedServletExceptionIsUnwrapped() throws Exception { this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500")); - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - super.doFilter(request, response); - throw new NestedServletException("Wrapper", new RuntimeException("BAD")); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + chain.call(); + throw new NestedServletException("Wrapper", new RuntimeException("BAD")); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()) .isEqualTo(500); @@ -524,15 +434,10 @@ public class ErrorPageFilterTests { @Test public void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient() throws Exception { - this.chain = new MockFilterChain() { - @Override - public void doFilter(ServletRequest request, ServletResponse response) - throws IOException, ServletException { - ((HttpServletResponse) response).sendError(400); - response.getWriter().flush(); - super.doFilter(request, response); - } - }; + this.chain = new TestFilterChain((request, response, chain) -> { + response.sendError(400); + response.getWriter().flush(); + }); this.filter.doFilter(this.request, this.response, this.chain); assertThat(this.response.getStatus()).isEqualTo(400); } @@ -551,6 +456,45 @@ public class ErrorPageFilterTests { return this.request.getDispatcher(path).getRequestAttributes(); } + private static class TestFilterChain extends MockFilterChain { + + private final FilterHandler handler; + + TestFilterChain(FilterHandler handler) { + this.handler = handler; + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response) + throws IOException, ServletException { + AtomicBoolean called = new AtomicBoolean(); + Chain chain = () -> { + if (called.compareAndSet(false, true)) { + super.doFilter(request, response); + } + }; + this.handler.handle((HttpServletRequest) request, + (HttpServletResponse) response, chain); + chain.call(); + } + + } + + @FunctionalInterface + private interface FilterHandler { + + void handle(HttpServletRequest request, HttpServletResponse response, Chain chain) + throws IOException, ServletException; + + } + + @FunctionalInterface + private interface Chain { + + void call() throws IOException, ServletException; + + } + private static final class DispatchRecordingMockHttpServletRequest extends MockHttpServletRequest {