Replace anonymous inner class with lambda

See gh-15438
pull/15692/head
igor-suhorukov 6 years ago committed by Stephane Nicoll
parent 3a7406fe3a
commit e578d30722

@ -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);
}

@ -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);
}
}

@ -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;
}
}

@ -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;
};
}

@ -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;
}
}

@ -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;
};
}

@ -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;
}
}

@ -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;
}
}

@ -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;
};
}

@ -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;
}
}

@ -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;
};
}

@ -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;
}
}

@ -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<Void> 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")))));
}
}

@ -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<Void> 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<Void> 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<Void> 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<Void> 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<Void> 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) {

@ -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<Authentication> authenticate(Authentication authentication) {
return null;
}
};
return (authentication) -> null;
}
}

@ -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];

@ -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<ApplicationReadyEvent> eventListener = mock(

@ -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<WebAppContext> contexts = server.getBeans(WebAppContext.class);
contexts.iterator().next().addEventListener(new ServletContextListener() {
@Override
public void customize(Server server) {
Collection<WebAppContext> 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();

@ -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);

Loading…
Cancel
Save