From e578d3072245836d865f787db1ebf79dfcd9c038 Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Tue, 11 Dec 2018 00:37:41 +0300 Subject: [PATCH] Replace anonymous inner class with lambda See gh-15438 --- ...theusScrapeEndpointDocumentationTests.java | 10 +--- ...iredConfigurationFailureAnalyzerTests.java | 10 +--- ...asMetricsExportAutoConfigurationTests.java | 9 +--- ...ogMetricsExportAutoConfigurationTests.java | 13 ++--- ...iaMetricsExportAutoConfigurationTests.java | 9 +--- ...teMetricsExportAutoConfigurationTests.java | 13 ++--- ...ioMetricsExportAutoConfigurationTests.java | 9 +--- ...uxMetricsExportAutoConfigurationTests.java | 9 +--- ...icMetricsExportAutoConfigurationTests.java | 19 +++---- ...usMetricsExportAutoConfigurationTests.java | 9 +--- ...FxMetricsExportAutoConfigurationTests.java | 13 ++--- ...leMetricsExportAutoConfigurationTests.java | 9 +--- .../WebFluxEndpointIntegrationTests.java | 22 ++------ .../reactive/HttpTraceWebFilterTests.java | 53 ++++--------------- ...rDetailsServiceAutoConfigurationTests.java | 9 +--- .../web/ServerPropertiesTests.java | 16 ++---- .../boot/SpringApplicationTests.java | 32 +++++------ .../JettyServletWebServerFactoryTests.java | 27 ++++------ ...rvletWebServerApplicationContextTests.java | 16 ++---- 19 files changed, 75 insertions(+), 232 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/PrometheusScrapeEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/PrometheusScrapeEndpointDocumentationTests.java index cc5f2945db..2b133d2c6b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/PrometheusScrapeEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/PrometheusScrapeEndpointDocumentationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentatio import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; -import io.micrometer.prometheus.PrometheusConfig; import io.micrometer.prometheus.PrometheusMeterRegistry; import io.prometheus.client.CollectorRegistry; import org.junit.Test; @@ -54,14 +53,7 @@ public class PrometheusScrapeEndpointDocumentationTests public PrometheusScrapeEndpoint endpoint() { CollectorRegistry collectorRegistry = new CollectorRegistry(true); PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry( - new PrometheusConfig() { - - @Override - public String get(String key) { - return null; - } - - }, collectorRegistry, Clock.SYSTEM); + (key) -> null, collectorRegistry, Clock.SYSTEM); new JvmMemoryMetrics().bindTo(meterRegistry); return new PrometheusScrapeEndpoint(collectorRegistry); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MissingRequiredConfigurationFailureAnalyzerTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MissingRequiredConfigurationFailureAnalyzerTests.java index a416208654..1e2d7cfb85 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MissingRequiredConfigurationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MissingRequiredConfigurationFailureAnalyzerTests.java @@ -17,7 +17,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics; import io.micrometer.core.instrument.Clock; -import io.micrometer.newrelic.NewRelicConfig; import io.micrometer.newrelic.NewRelicMeterRegistry; import org.junit.Test; @@ -64,14 +63,7 @@ public class MissingRequiredConfigurationFailureAnalyzerTests { @Bean public NewRelicMeterRegistry meterRegistry() { - return new NewRelicMeterRegistry(new NewRelicConfig() { - - @Override - public String get(String key) { - return null; - } - - }, Clock.SYSTEM); + return new NewRelicMeterRegistry((key) -> null, Clock.SYSTEM); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasMetricsExportAutoConfigurationTests.java index 3aa658f79c..93dc4a0671 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasMetricsExportAutoConfigurationTests.java @@ -107,14 +107,7 @@ public class AtlasMetricsExportAutoConfigurationTests { @Bean public AtlasConfig customConfig() { - return new AtlasConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogMetricsExportAutoConfigurationTests.java index 767f9db80d..55527f9e05 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogMetricsExportAutoConfigurationTests.java @@ -116,16 +116,11 @@ public class DatadogMetricsExportAutoConfigurationTests { @Bean public DatadogConfig customConfig() { - return new DatadogConfig() { - - @Override - public String get(String k) { - if ("datadog.apiKey".equals(k)) { - return "12345"; - } - return null; + return (k) -> { + if ("datadog.apiKey".equals(k)) { + return "12345"; } - + return null; }; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfigurationTests.java index 3fcc29c05b..8fb5036115 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaMetricsExportAutoConfigurationTests.java @@ -107,14 +107,7 @@ public class GangliaMetricsExportAutoConfigurationTests { @Bean public GangliaConfig customConfig() { - return new GangliaConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } 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 5734396e55..0a8af33424 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 @@ -124,16 +124,11 @@ public class GraphiteMetricsExportAutoConfigurationTests { @Bean public GraphiteConfig customConfig() { - return new GraphiteConfig() { - - @Override - public String get(String k) { - if ("Graphite.apiKey".equals(k)) { - return "12345"; - } - return null; + return (k) -> { + if ("Graphite.apiKey".equals(k)) { + return "12345"; } - + return null; }; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioMetricsExportAutoConfigurationTests.java index 8add7fb275..f3d863f100 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioMetricsExportAutoConfigurationTests.java @@ -109,14 +109,7 @@ public class HumioMetricsExportAutoConfigurationTests { @Bean public HumioConfig customConfig() { - return new HumioConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxMetricsExportAutoConfigurationTests.java index 04c5cb6687..2f490c2b21 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxMetricsExportAutoConfigurationTests.java @@ -107,14 +107,7 @@ public class InfluxMetricsExportAutoConfigurationTests { @Bean public InfluxConfig customConfig() { - return new InfluxConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfigurationTests.java index 56d9470d9d..f3e3d53559 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfigurationTests.java @@ -129,19 +129,14 @@ public class NewRelicMetricsExportAutoConfigurationTests { @Bean public NewRelicConfig customConfig() { - return new NewRelicConfig() { - - @Override - public String get(String k) { - if ("newrelic.accountId".equals(k)) { - return "abcde"; - } - if ("newrelic.apiKey".equals(k)) { - return "12345"; - } - return null; + return (k) -> { + if ("newrelic.accountId".equals(k)) { + return "abcde"; } - + if ("newrelic.apiKey".equals(k)) { + return "12345"; + } + return null; }; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java index 52f80208d8..7fbb5076ad 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java @@ -157,14 +157,7 @@ public class PrometheusMetricsExportAutoConfigurationTests { @Bean public PrometheusConfig customConfig() { - return new PrometheusConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxMetricsExportAutoConfigurationTests.java index b5a38f9b97..ceb048df95 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxMetricsExportAutoConfigurationTests.java @@ -124,16 +124,11 @@ public class SignalFxMetricsExportAutoConfigurationTests { @Bean public SignalFxConfig customConfig() { - return new SignalFxConfig() { - - @Override - public String get(String k) { - if ("signalfx.accessToken".equals(k)) { - return "abcde"; - } - return null; + return (k) -> { + if ("signalfx.accessToken".equals(k)) { + return "abcde"; } - + return null; }; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfigurationTests.java index e14c83b881..fb79339bb2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfigurationTests.java @@ -90,14 +90,7 @@ public class SimpleMetricsExportAutoConfigurationTests { @Bean public SimpleConfig customConfig() { - return new SimpleConfig() { - - @Override - public String get(String k) { - return null; - } - - }; + return (k) -> null; } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java index 8632b14ef7..706fedec31 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint.web.reactive; import java.util.Arrays; import org.junit.Test; -import reactor.core.publisher.Mono; import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver; import org.springframework.boot.actuate.endpoint.web.EndpointMapping; @@ -44,9 +43,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.reactive.config.EnableWebFlux; -import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; -import org.springframework.web.server.WebFilterChain; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -148,20 +145,11 @@ public class WebFluxEndpointIntegrationTests extends @Bean public WebFilter webFilter() { - return new WebFilter() { - - @Override - public Mono filter(ServerWebExchange exchange, - WebFilterChain chain) { - return chain.filter(exchange).subscriberContext( - ReactiveSecurityContextHolder.withAuthentication( - new UsernamePasswordAuthenticationToken("Alice", - "secret", - Arrays.asList(new SimpleGrantedAuthority( - "ROLE_ACTUATOR"))))); - } - - }; + return (exchange, chain) -> chain.filter(exchange) + .subscriberContext(ReactiveSecurityContextHolder.withAuthentication( + new UsernamePasswordAuthenticationToken("Alice", "secret", + Arrays.asList(new SimpleGrantedAuthority( + "ROLE_ACTUATOR"))))); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java index 2bc1890bf3..a1471a9792 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java @@ -33,9 +33,7 @@ import org.springframework.boot.actuate.trace.http.Include; import org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; -import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchangeDecorator; -import org.springframework.web.server.WebFilterChain; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -62,14 +60,7 @@ public class HttpTraceWebFilterTests { this.filter.filter( MockServerWebExchange .from(MockServerHttpRequest.get("https://api.example.com")), - new WebFilterChain() { - - @Override - public Mono filter(ServerWebExchange exchange) { - return Mono.empty(); - } - - }).block(Duration.ofSeconds(30)); + (exchange) -> Mono.empty()).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); } @@ -79,15 +70,10 @@ public class HttpTraceWebFilterTests { this.filter.filter( MockServerWebExchange .from(MockServerHttpRequest.get("https://api.example.com")), - new WebFilterChain() { - - @Override - public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block(Duration.ofSeconds(30)) + (exchange) -> { + exchange.getSession().block(Duration.ofSeconds(30)) .getAttributes().put("a", "alpha"); - return Mono.empty(); - } - + return Mono.empty(); }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); Session session = this.repository.findAll().get(0).getSession(); @@ -101,14 +87,9 @@ public class HttpTraceWebFilterTests { this.filter.filter( MockServerWebExchange .from(MockServerHttpRequest.get("https://api.example.com")), - new WebFilterChain() { - - @Override - public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block(Duration.ofSeconds(30)); - return Mono.empty(); - } - + (exchange) -> { + exchange.getSession().block(Duration.ofSeconds(30)); + return Mono.empty(); }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); Session session = this.repository.findAll().get(0).getSession(); @@ -127,15 +108,10 @@ public class HttpTraceWebFilterTests { return Mono.just(principal); } - }, new WebFilterChain() { - - @Override - public Mono filter(ServerWebExchange exchange) { - exchange.getSession().block(Duration.ofSeconds(30)).getAttributes() + }, (exchange) -> { + exchange.getSession().block(Duration.ofSeconds(30)).getAttributes() .put("a", "alpha"); - return Mono.empty(); - } - + return Mono.empty(); }).block(Duration.ofSeconds(30)); assertThat(this.repository.findAll()).hasSize(1); org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository @@ -151,14 +127,7 @@ public class HttpTraceWebFilterTests { this.filter.filter( MockServerWebExchange .from(MockServerHttpRequest.get("https://api.example.com")), - new WebFilterChain() { - - @Override - public Mono filter(ServerWebExchange exchange) { - return Mono.error(new RuntimeException()); - } - - }).block(Duration.ofSeconds(30)); + (exchange) -> Mono.error(new RuntimeException())).block(Duration.ofSeconds(30)); fail(); } catch (Exception ex) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java index 7dfeeb07f9..f1e87866e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfigurationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.security.reactive; import java.time.Duration; import org.junit.Test; -import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.security.SecurityProperties; @@ -30,7 +29,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; -import org.springframework.security.core.Authentication; import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; import org.springframework.security.core.userdetails.ReactiveUserDetailsService; import org.springframework.security.core.userdetails.User; @@ -156,12 +154,7 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests { @Bean public ReactiveAuthenticationManager reactiveAuthenticationManager() { - return new ReactiveAuthenticationManager() { - @Override - public Mono authenticate(Authentication authentication) { - return null; - } - }; + return (authentication) -> null; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 64bcafe250..928f7bff52 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -270,13 +269,9 @@ public class ServerPropertiesTests { @Test public void jettyMaxHttpPostSizeMatchesDefault() throws Exception { JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0); - JettyWebServer jetty = (JettyWebServer) jettyFactory - .getWebServer(new ServletContextInitializer() { - - @Override - public void onStartup(ServletContext servletContext) - throws ServletException { - servletContext.addServlet("formPost", new HttpServlet() { + JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer( + (ServletContextInitializer) (servletContext) -> servletContext + .addServlet("formPost", new HttpServlet() { @Override protected void doPost(HttpServletRequest req, @@ -285,10 +280,7 @@ public class ServerPropertiesTests { req.getParameterMap(); } - }).addMapping("/form"); - } - - }); + }).addMapping("/form")); jetty.start(); org.eclipse.jetty.server.Connector connector = jetty.getServer() .getConnectors()[0]; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 522adaeb24..5c421e0f0b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -669,26 +669,18 @@ public class SpringApplicationTests { CommandLineRunner commandLineRunner = mock(CommandLineRunner.class); application.addInitializers((context) -> { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); - beanFactory.registerSingleton("commandLineRunner", new CommandLineRunner() { - - @Override - public void run(String... args) throws Exception { - assertThat(SpringApplicationTests.this.output.toString()) - .contains("Started"); - commandLineRunner.run(args); - } - - }); - beanFactory.registerSingleton("applicationRunner", new ApplicationRunner() { - - @Override - public void run(ApplicationArguments args) throws Exception { - assertThat(SpringApplicationTests.this.output.toString()) - .contains("Started"); - applicationRunner.run(args); - } - - }); + beanFactory.registerSingleton("commandLineRunner", + (CommandLineRunner) (args) -> { + assertThat(SpringApplicationTests.this.output.toString()) + .contains("Started"); + commandLineRunner.run(args); + }); + beanFactory.registerSingleton("applicationRunner", + (ApplicationRunner) (args) -> { + assertThat(SpringApplicationTests.this.output.toString()) + .contains("Started"); + applicationRunner.run(args); + }); }); application.setWebApplicationType(WebApplicationType.NONE); ApplicationListener eventListener = mock( diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index 315643faad..22579828bc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java @@ -301,25 +301,20 @@ public class JettyServletWebServerFactoryTests @Test public void faultyListenerCausesStartFailure() throws Exception { JettyServletWebServerFactory factory = getFactory(); - factory.addServerCustomizers(new JettyServerCustomizer() { + factory.addServerCustomizers((JettyServerCustomizer) (server) -> { + Collection contexts = server.getBeans(WebAppContext.class); + contexts.iterator().next().addEventListener(new ServletContextListener() { - @Override - public void customize(Server server) { - Collection contexts = server.getBeans(WebAppContext.class); - contexts.iterator().next().addEventListener(new ServletContextListener() { + @Override + public void contextInitialized(ServletContextEvent sce) { + throw new RuntimeException(); + } - @Override - public void contextInitialized(ServletContextEvent sce) { - throw new RuntimeException(); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - } - - }); - } + @Override + public void contextDestroyed(ServletContextEvent sce) { + } + }); }); assertThatExceptionOfType(WebServerException.class).isThrownBy(() -> { JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java index 64fa1085d6..f233de8a79 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java @@ -38,11 +38,9 @@ import org.mockito.Captor; import org.mockito.InOrder; import org.mockito.MockitoAnnotations; -import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.Scope; @@ -475,16 +473,10 @@ public class ServletWebServerApplicationContextTests { beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR); this.context.registerBeanDefinition("withAutowiredServletRequest", beanDefinition); - this.context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { - - @Override - public void postProcessBeanFactory( - ConfigurableListableBeanFactory beanFactory) throws BeansException { - WithAutowiredServletRequest bean = beanFactory - .getBean(WithAutowiredServletRequest.class); - assertThat(bean.getRequest()).isNotNull(); - } - + this.context.addBeanFactoryPostProcessor((beanFactory) -> { + WithAutowiredServletRequest bean = beanFactory + .getBean(WithAutowiredServletRequest.class); + assertThat(bean.getRequest()).isNotNull(); }); this.context.refresh(); String output = this.output.toString().substring(initialOutputLength);