Use pattern matching for instanceof where appropriate

See gh-31475
This commit is contained in:
dreis2211
2022-06-20 18:14:16 +02:00
committed by Andy Wilkinson
parent a7b98e7312
commit 5db04da275
278 changed files with 1049 additions and 1126 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -64,8 +64,8 @@ public class BeansEndpoint {
private static ConfigurableApplicationContext getConfigurableParent(ConfigurableApplicationContext context) {
ApplicationContext parent = context.getParent();
if (parent instanceof ConfigurableApplicationContext) {
return (ConfigurableApplicationContext) parent;
if (parent instanceof ConfigurableApplicationContext configurableParent) {
return configurableParent;
}
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -72,8 +72,8 @@ public class ShutdownEndpoint implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
if (context instanceof ConfigurableApplicationContext) {
this.context = (ConfigurableApplicationContext) context;
if (context instanceof ConfigurableApplicationContext configurableContext) {
this.context = configurableContext;
}
}

View File

@@ -434,9 +434,9 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
@Override
public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider provider,
PropertyWriter writer) throws Exception {
if (writer instanceof BeanPropertyWriter) {
if (writer instanceof BeanPropertyWriter beanPropertyWriter) {
try {
if (pojo == ((BeanPropertyWriter) writer).get(pojo)) {
if (pojo == beanPropertyWriter.get(pojo)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping '" + writer.getFullName() + "' on '" + pojo.getClass().getName()
+ "' as it is self-referential");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -70,11 +70,11 @@ public class EndpointLinksResolver {
Map<String, Link> links = new LinkedHashMap<>();
links.put("self", new Link(normalizedUrl));
for (ExposableEndpoint<?> endpoint : this.endpoints) {
if (endpoint instanceof ExposableWebEndpoint) {
collectLinks(links, (ExposableWebEndpoint) endpoint, normalizedUrl);
if (endpoint instanceof ExposableWebEndpoint exposableWebEndpoint) {
collectLinks(links, exposableWebEndpoint, normalizedUrl);
}
else if (endpoint instanceof PathMappedEndpoint) {
String rootPath = ((PathMappedEndpoint) endpoint).getRootPath();
else if (endpoint instanceof PathMappedEndpoint pathMappedEndpoint) {
String rootPath = pathMappedEndpoint.getRootPath();
Link link = createLink(normalizedUrl, rootPath);
links.put(endpoint.getEndpointId().toLowerCaseString(), link);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -66,8 +66,8 @@ public class PathMappedEndpoints implements Iterable<PathMappedEndpoint> {
private Map<EndpointId, PathMappedEndpoint> getEndpoints(Collection<EndpointsSupplier<?>> suppliers) {
Map<EndpointId, PathMappedEndpoint> endpoints = new LinkedHashMap<>();
suppliers.forEach((supplier) -> supplier.getEndpoints().forEach((endpoint) -> {
if (endpoint instanceof PathMappedEndpoint) {
endpoints.put(endpoint.getEndpointId(), (PathMappedEndpoint) endpoint);
if (endpoint instanceof PathMappedEndpoint pathMappedEndpoint) {
endpoints.put(endpoint.getEndpointId(), pathMappedEndpoint);
}
}));
return Collections.unmodifiableMap(endpoints);

View File

@@ -176,15 +176,15 @@ public class EnvironmentEndpoint {
}
private MutablePropertySources getPropertySources() {
if (this.environment instanceof ConfigurableEnvironment) {
return ((ConfigurableEnvironment) this.environment).getPropertySources();
if (this.environment instanceof ConfigurableEnvironment configurableEnvironment) {
return configurableEnvironment.getPropertySources();
}
return new StandardEnvironment().getPropertySources();
}
private void extract(String root, Map<String, PropertySource<?>> map, PropertySource<?> source) {
if (source instanceof CompositePropertySource) {
for (PropertySource<?> nest : ((CompositePropertySource) source).getPropertySources()) {
if (source instanceof CompositePropertySource compositePropertySource) {
for (PropertySource<?> nest : compositePropertySource.getPropertySources()) {
extract(source.getName() + ":", map, nest);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -88,10 +88,10 @@ public abstract class AbstractHealthIndicator implements HealthIndicator {
return builder.build();
}
private void logExceptionIfPresent(Throwable ex) {
if (ex != null && this.logger.isWarnEnabled()) {
String message = (ex instanceof Exception) ? this.healthCheckFailedMessage.apply((Exception) ex) : null;
this.logger.warn(StringUtils.hasText(message) ? message : DEFAULT_MESSAGE, ex);
private void logExceptionIfPresent(Throwable throwable) {
if (throwable != null && this.logger.isWarnEnabled()) {
String message = (throwable instanceof Exception ex) ? this.healthCheckFailedMessage.apply(ex) : null;
this.logger.warn(StringUtils.hasText(message) ? message : DEFAULT_MESSAGE, throwable);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -106,8 +106,7 @@ public final class Health extends HealthComponent {
if (obj == this) {
return true;
}
if (obj instanceof Health) {
Health other = (Health) obj;
if (obj instanceof Health other) {
return this.status.equals(other.status) && this.details.equals(other.details);
}
return false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -33,11 +33,11 @@ public interface ReactiveHealthContributor {
static ReactiveHealthContributor adapt(HealthContributor healthContributor) {
Assert.notNull(healthContributor, "HealthContributor must not be null");
if (healthContributor instanceof HealthIndicator) {
return new HealthIndicatorReactiveAdapter((HealthIndicator) healthContributor);
if (healthContributor instanceof HealthIndicator healthIndicator) {
return new HealthIndicatorReactiveAdapter(healthIndicator);
}
if (healthContributor instanceof CompositeHealthContributor) {
return new CompositeHealthContributorReactiveAdapter((CompositeHealthContributor) healthContributor);
if (healthContributor instanceof CompositeHealthContributor compositeHealthContributor) {
return new CompositeHealthContributorReactiveAdapter(compositeHealthContributor);
}
throw new IllegalStateException("Unknown HealthContributor type");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -107,8 +107,8 @@ public final class Status {
if (obj == this) {
return true;
}
if (obj instanceof Status) {
return ObjectUtils.nullSafeEquals(this.code, ((Status) obj).code);
if (obj instanceof Status other) {
return ObjectUtils.nullSafeEquals(this.code, other.code);
}
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -71,8 +71,7 @@ public final class Info {
if (obj == this) {
return true;
}
if (obj instanceof Info) {
Info other = (Info) obj;
if (obj instanceof Info other) {
return this.details.equals(other.details);
}
return false;

View File

@@ -64,8 +64,8 @@ public class MetricsEndpoint {
}
private void collectNames(Set<String> names, MeterRegistry registry) {
if (registry instanceof CompositeMeterRegistry) {
((CompositeMeterRegistry) registry).getRegistries().forEach((member) -> collectNames(names, member));
if (registry instanceof CompositeMeterRegistry compositeMeterRegistry) {
compositeMeterRegistry.getRegistries().forEach((member) -> collectNames(names, member));
}
else {
registry.getMeters().stream().map(this::getName).forEach(names::add);
@@ -109,8 +109,8 @@ public class MetricsEndpoint {
}
private Collection<Meter> findFirstMatchingMeters(MeterRegistry registry, String name, Iterable<Tag> tags) {
if (registry instanceof CompositeMeterRegistry) {
return findFirstMatchingMeters((CompositeMeterRegistry) registry, name, tags);
if (registry instanceof CompositeMeterRegistry compositeMeterRegistry) {
return findFirstMatchingMeters(compositeMeterRegistry, name, tags);
}
return registry.find(name).tags(tags).meters();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -98,8 +98,8 @@ public class CacheMetricsRegistrar {
private static Cache unwrapIfNecessary(Cache cache) {
try {
if (cache instanceof TransactionAwareCacheDecorator) {
return ((TransactionAwareCacheDecorator) cache).getTargetCache();
if (cache instanceof TransactionAwareCacheDecorator decorator) {
return decorator.getTargetCache();
}
}
catch (NoClassDefFoundError ex) {

View File

@@ -136,8 +136,8 @@ public class PrometheusPushGatewayManager {
}
private void shutdown(ShutdownOperation shutdownOperation) {
if (this.scheduler instanceof PushGatewayTaskScheduler) {
((PushGatewayTaskScheduler) this.scheduler).shutdown();
if (this.scheduler instanceof PushGatewayTaskScheduler pushGatewayTaskScheduler) {
pushGatewayTaskScheduler.shutdown();
}
this.scheduled.cancel(false);
switch (shutdownOperation) {

View File

@@ -94,11 +94,11 @@ public class StartupTimeMetricsListener implements SmartApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationStartedEvent) {
onApplicationStarted((ApplicationStartedEvent) event);
if (event instanceof ApplicationStartedEvent startedEvent) {
onApplicationStarted(startedEvent);
}
if (event instanceof ApplicationReadyEvent) {
onApplicationReady((ApplicationReadyEvent) event);
if (event instanceof ApplicationReadyEvent readyEvent) {
onApplicationReady(readyEvent);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -105,8 +105,8 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
}
UriTemplateHandler createUriTemplateHandler(UriTemplateHandler delegate) {
if (delegate instanceof RootUriTemplateHandler) {
return ((RootUriTemplateHandler) delegate).withHandlerWrapper(CapturingUriTemplateHandler::new);
if (delegate instanceof RootUriTemplateHandler rootHandler) {
return rootHandler.withHandlerWrapper(CapturingUriTemplateHandler::new);
}
return new CapturingUriTemplateHandler(delegate);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -42,10 +42,10 @@ public abstract class AbstractJettyMetricsBinder implements ApplicationListener<
}
private Server findServer(ApplicationContext applicationContext) {
if (applicationContext instanceof WebServerApplicationContext) {
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
if (webServer instanceof JettyWebServer) {
return ((JettyWebServer) webServer).getServer();
if (applicationContext instanceof WebServerApplicationContext webServerApplicationContext) {
WebServer webServer = webServerApplicationContext.getWebServer();
if (webServer instanceof JettyWebServer jettyWebServer) {
return jettyWebServer.getServer();
}
}
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -118,8 +118,7 @@ public class MetricsWebFilter implements WebFilter {
}
private Set<Timed> getTimedAnnotations(Object handler) {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handler instanceof HandlerMethod handlerMethod) {
return TimedAnnotations.get(handlerMethod.getMethod(), handlerMethod.getBeanType());
}
return Collections.emptySet();

View File

@@ -109,10 +109,10 @@ public class LongTaskTimingHandlerInterceptor implements HandlerInterceptor {
}
private Set<Timed> getTimedAnnotations(Object handler) {
if (!(handler instanceof HandlerMethod)) {
return Collections.emptySet();
if (handler instanceof HandlerMethod handlerMethod) {
return getTimedAnnotations(handlerMethod);
}
return getTimedAnnotations((HandlerMethod) handler);
return Collections.emptySet();
}
private Set<Timed> getTimedAnnotations(HandlerMethod handler) {

View File

@@ -147,8 +147,7 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
}
private Set<Timed> getTimedAnnotations(Object handler) {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handler instanceof HandlerMethod handlerMethod) {
return TimedAnnotations.get(handlerMethod.getMethod(), handlerMethod.getBeanType());
}
return Collections.emptySet();

View File

@@ -65,10 +65,10 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart
}
private Manager findManager(ApplicationContext applicationContext) {
if (applicationContext instanceof WebServerApplicationContext) {
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
if (webServer instanceof TomcatWebServer) {
Context context = findContext((TomcatWebServer) webServer);
if (applicationContext instanceof WebServerApplicationContext webServerApplicationContext) {
WebServer webServer = webServerApplicationContext.getWebServer();
if (webServer instanceof TomcatWebServer tomcatWebServer) {
Context context = findContext(tomcatWebServer);
if (context != null) {
return context.getManager();
}
@@ -79,8 +79,8 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart
private Context findContext(TomcatWebServer tomcatWebServer) {
for (Container container : tomcatWebServer.getTomcat().getHost().findChildren()) {
if (container instanceof Context) {
return (Context) container;
if (container instanceof Context context) {
return context;
}
}
return null;

View File

@@ -56,8 +56,8 @@ public class RedisHealthIndicator extends AbstractHealthIndicator {
}
private void doHealthCheck(Health.Builder builder, RedisConnection connection) {
if (connection instanceof RedisClusterConnection) {
RedisHealth.fromClusterInfo(builder, ((RedisClusterConnection) connection).clusterGetClusterInfo());
if (connection instanceof RedisClusterConnection clusterConnection) {
RedisHealth.fromClusterInfo(builder, clusterConnection.clusterGetClusterInfo());
}
else {
RedisHealth.up(builder, connection.serverCommands().info());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -63,9 +63,8 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
}
private Mono<Health> getHealth(Health.Builder builder, ReactiveRedisConnection connection) {
if (connection instanceof ReactiveRedisClusterConnection) {
return ((ReactiveRedisClusterConnection) connection).clusterGetClusterInfo()
.map((info) -> fromClusterInfo(builder, info));
if (connection instanceof ReactiveRedisClusterConnection clusterConnection) {
return clusterConnection.clusterGetClusterInfo().map((info) -> fromClusterInfo(builder, info));
}
return connection.serverCommands().info("server").map((info) -> up(builder, info));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -130,11 +130,10 @@ public class ScheduledTasksEndpoint {
private static TaskDescription describeTriggerTask(TriggerTask triggerTask) {
Trigger trigger = triggerTask.getTrigger();
if (trigger instanceof CronTrigger) {
return new CronTaskDescription(triggerTask, (CronTrigger) trigger);
if (trigger instanceof CronTrigger cronTrigger) {
return new CronTaskDescription(triggerTask, cronTrigger);
}
if (trigger instanceof PeriodicTrigger) {
PeriodicTrigger periodicTrigger = (PeriodicTrigger) trigger;
if (trigger instanceof PeriodicTrigger periodicTrigger) {
if (periodicTrigger.isFixedRate()) {
return new FixedRateTaskDescription(triggerTask, periodicTrigger);
}
@@ -275,8 +274,8 @@ public class ScheduledTasksEndpoint {
private final String target;
private RunnableDescription(Runnable runnable) {
if (runnable instanceof ScheduledMethodRunnable) {
Method method = ((ScheduledMethodRunnable) runnable).getMethod();
if (runnable instanceof ScheduledMethodRunnable scheduledMethodRunnable) {
Method method = scheduledMethodRunnable.getMethod();
this.target = method.getDeclaringClass().getName() + "." + method.getName();
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -63,14 +63,14 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AbstractAuthenticationFailureEvent) {
onAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
if (event instanceof AbstractAuthenticationFailureEvent failureEvent) {
onAuthenticationFailureEvent(failureEvent);
}
else if (this.webListener != null && this.webListener.accepts(event)) {
this.webListener.process(this, event);
}
else if (event instanceof AuthenticationSuccessEvent) {
onAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
else if (event instanceof AuthenticationSuccessEvent successEvent) {
onAuthenticationSuccessEvent(successEvent);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -40,11 +40,11 @@ public class AuthorizationAuditListener extends AbstractAuthorizationAuditListen
@Override
public void onApplicationEvent(AbstractAuthorizationEvent event) {
if (event instanceof AuthenticationCredentialsNotFoundEvent) {
onAuthenticationCredentialsNotFoundEvent((AuthenticationCredentialsNotFoundEvent) event);
if (event instanceof AuthenticationCredentialsNotFoundEvent credentialsNotFoundEvent) {
onAuthenticationCredentialsNotFoundEvent(credentialsNotFoundEvent);
}
else if (event instanceof AuthorizationFailureEvent) {
onAuthorizationFailureEvent((AuthorizationFailureEvent) event);
else if (event instanceof AuthorizationFailureEvent authorizationFailureEvent) {
onAuthorizationFailureEvent(authorizationFailureEvent);
}
}

View File

@@ -66,15 +66,15 @@ final class DispatcherServletHandlerMappings {
}
private void initializeDispatcherServletIfPossible() {
if (!(this.applicationContext instanceof ServletWebServerApplicationContext)) {
if (!(this.applicationContext instanceof ServletWebServerApplicationContext webServerApplicationContext)) {
return;
}
WebServer webServer = ((ServletWebServerApplicationContext) this.applicationContext).getWebServer();
if (webServer instanceof UndertowServletWebServer) {
new UndertowServletInitializer((UndertowServletWebServer) webServer).initializeServlet(this.name);
WebServer webServer = webServerApplicationContext.getWebServer();
if (webServer instanceof UndertowServletWebServer undertowServletWebServer) {
new UndertowServletInitializer(undertowServletWebServer).initializeServlet(this.name);
}
else if (webServer instanceof TomcatWebServer) {
new TomcatServletInitializer((TomcatWebServer) webServer).initializeServlet(this.name);
else if (webServer instanceof TomcatWebServer tomcatWebServer) {
new TomcatServletInitializer(tomcatWebServer).initializeServlet(this.name);
}
}
@@ -101,9 +101,8 @@ final class DispatcherServletHandlerMappings {
private void initializeServlet(Context context, String name) {
Container child = context.findChild(name);
if (child instanceof StandardWrapper) {
if (child instanceof StandardWrapper wrapper) {
try {
StandardWrapper wrapper = (StandardWrapper) child;
wrapper.deallocate(wrapper.allocate());
}
catch (ServletException ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -68,8 +68,8 @@ public class DispatcherServletsMappingDescriptionProvider implements MappingDesc
@Override
public Map<String, List<DispatcherServletMappingDescription>> describeMappings(ApplicationContext context) {
if (context instanceof WebApplicationContext) {
return describeMappings((WebApplicationContext) context);
if (context instanceof WebApplicationContext webApplicationContext) {
return describeMappings(webApplicationContext);
}
return Collections.emptyMap();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -38,11 +38,11 @@ public class FiltersMappingDescriptionProvider implements MappingDescriptionProv
@Override
public List<FilterRegistrationMappingDescription> describeMappings(ApplicationContext context) {
if (!(context instanceof WebApplicationContext)) {
return Collections.emptyList();
if (context instanceof WebApplicationContext webApplicationContext) {
return webApplicationContext.getServletContext().getFilterRegistrations().values().stream()
.map(FilterRegistrationMappingDescription::new).collect(Collectors.toList());
}
return ((WebApplicationContext) context).getServletContext().getFilterRegistrations().values().stream()
.map(FilterRegistrationMappingDescription::new).collect(Collectors.toList());
return Collections.emptyList();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -38,11 +38,11 @@ public class ServletsMappingDescriptionProvider implements MappingDescriptionPro
@Override
public List<ServletRegistrationMappingDescription> describeMappings(ApplicationContext context) {
if (!(context instanceof WebApplicationContext)) {
return Collections.emptyList();
if (context instanceof WebApplicationContext webApplicationContext) {
return webApplicationContext.getServletContext().getServletRegistrations().values().stream()
.map(ServletRegistrationMappingDescription::new).collect(Collectors.toList());
}
return ((WebApplicationContext) context).getServletContext().getServletRegistrations().values().stream()
.map(ServletRegistrationMappingDescription::new).collect(Collectors.toList());
return Collections.emptyList();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -183,8 +183,8 @@ class WebEndpointTestInvocationContextProvider implements TestTemplateInvocation
}
private int determinePort() {
if (this.context instanceof AnnotationConfigServletWebServerApplicationContext) {
return ((AnnotationConfigServletWebServerApplicationContext) this.context).getWebServer().getPort();
if (this.context instanceof AnnotationConfigServletWebServerApplicationContext webServerContext) {
return webServerContext.getWebServer().getPort();
}
return this.context.getBean(PortHolder.class).getPort();
}