Apply "instanceof pattern matching" Eclipse clean-up in spring-test
This has only been applied to `src/main/java`.
This commit is contained in:
parent
4fc359f75e
commit
7e4870577d
|
@ -1279,8 +1279,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
|
||||
public void setSession(HttpSession session) {
|
||||
this.session = session;
|
||||
if (session instanceof MockHttpSession) {
|
||||
MockHttpSession mockSession = ((MockHttpSession) session);
|
||||
if (session instanceof MockHttpSession mockSession) {
|
||||
mockSession.access();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,8 +444,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
if (cookie.isHttpOnly()) {
|
||||
buf.append("; HttpOnly");
|
||||
}
|
||||
if (cookie instanceof MockCookie) {
|
||||
MockCookie mockCookie = (MockCookie) cookie;
|
||||
if (cookie instanceof MockCookie mockCookie) {
|
||||
if (StringUtils.hasText(mockCookie.getSameSite())) {
|
||||
buf.append("; SameSite=").append(mockCookie.getSameSite());
|
||||
}
|
||||
|
|
|
@ -335,10 +335,9 @@ public class ContextConfigurationAttributes {
|
|||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof ContextConfigurationAttributes)) {
|
||||
if (!(other instanceof ContextConfigurationAttributes otherAttr)) {
|
||||
return false;
|
||||
}
|
||||
ContextConfigurationAttributes otherAttr = (ContextConfigurationAttributes) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.declaringClass, otherAttr.declaringClass) &&
|
||||
Arrays.equals(this.classes, otherAttr.classes)) &&
|
||||
Arrays.equals(this.locations, otherAttr.locations) &&
|
||||
|
|
|
@ -94,8 +94,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
|
|||
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
if (contextLoader instanceof SmartContextLoader) {
|
||||
SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
|
||||
if (contextLoader instanceof SmartContextLoader smartContextLoader) {
|
||||
applicationContext = smartContextLoader.loadContext(mergedContextConfiguration);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
|
@ -58,8 +58,8 @@ class DefaultApplicationEvents implements ApplicationEvents {
|
|||
}
|
||||
|
||||
private Object unwrapPayloadEvent(Object source) {
|
||||
return (PayloadApplicationEvent.class.isInstance(source) ?
|
||||
((PayloadApplicationEvent<?>) source).getPayload() : source);
|
||||
return ((source instanceof PayloadApplicationEvent<?> payloadApplicationEvent) ?
|
||||
payloadApplicationEvent.getPayload() : source);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -352,8 +352,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
|||
logger.trace(String.format("Processing locations and classes for context configuration attributes %s",
|
||||
configAttributes));
|
||||
}
|
||||
if (contextLoader instanceof SmartContextLoader) {
|
||||
SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
|
||||
if (contextLoader instanceof SmartContextLoader smartContextLoader) {
|
||||
smartContextLoader.processContextConfiguration(configAttributes);
|
||||
locations.addAll(0, Arrays.asList(configAttributes.getLocations()));
|
||||
classes.addAll(0, Arrays.asList(configAttributes.getClasses()));
|
||||
|
|
|
@ -122,9 +122,7 @@ public class DefaultTestContext implements TestContext {
|
|||
@Override
|
||||
public ApplicationContext getApplicationContext() {
|
||||
ApplicationContext context = this.cacheAwareContextLoaderDelegate.loadContext(this.mergedContextConfiguration);
|
||||
if (context instanceof ConfigurableApplicationContext) {
|
||||
@SuppressWarnings("resource")
|
||||
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
|
||||
if (context instanceof ConfigurableApplicationContext cac) {
|
||||
Assert.state(cac.isActive(), () ->
|
||||
"The ApplicationContext loaded for [" + this.mergedContextConfiguration +
|
||||
"] is not active. This may be due to one of the following reasons: " +
|
||||
|
|
|
@ -106,9 +106,7 @@ public abstract class TestContextTransactionUtils {
|
|||
}
|
||||
|
||||
try {
|
||||
if (bf instanceof ListableBeanFactory) {
|
||||
ListableBeanFactory lbf = (ListableBeanFactory) bf;
|
||||
|
||||
if (bf instanceof ListableBeanFactory lbf) {
|
||||
// Look up single bean by type
|
||||
Map<String, DataSource> dataSources =
|
||||
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DataSource.class);
|
||||
|
@ -180,9 +178,7 @@ public abstract class TestContextTransactionUtils {
|
|||
}
|
||||
|
||||
try {
|
||||
if (bf instanceof ListableBeanFactory) {
|
||||
ListableBeanFactory lbf = (ListableBeanFactory) bf;
|
||||
|
||||
if (bf instanceof ListableBeanFactory lbf) {
|
||||
// Look up single TransactionManagementConfigurer
|
||||
Map<String, TransactionManagementConfigurer> configurers =
|
||||
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, TransactionManagementConfigurer.class);
|
||||
|
|
|
@ -188,8 +188,7 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
|
|||
|
||||
ApplicationContext context = testContext.getApplicationContext();
|
||||
|
||||
if (context instanceof WebApplicationContext) {
|
||||
WebApplicationContext wac = (WebApplicationContext) context;
|
||||
if (context instanceof WebApplicationContext wac) {
|
||||
ServletContext servletContext = wac.getServletContext();
|
||||
Assert.state(servletContext instanceof MockServletContext, () -> String.format(
|
||||
"The WebApplicationContext for test context %s must be configured with a MockServletContext.",
|
||||
|
@ -211,9 +210,7 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
|
|||
testContext.setAttribute(POPULATED_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);
|
||||
testContext.setAttribute(RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE, Boolean.TRUE);
|
||||
|
||||
if (wac instanceof ConfigurableApplicationContext) {
|
||||
@SuppressWarnings("resource")
|
||||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) wac;
|
||||
if (wac instanceof ConfigurableApplicationContext configurableApplicationContext) {
|
||||
ConfigurableListableBeanFactory bf = configurableApplicationContext.getBeanFactory();
|
||||
bf.registerResolvableDependency(MockHttpServletResponse.class, response);
|
||||
bf.registerResolvableDependency(ServletWebRequest.class, servletWebRequest);
|
||||
|
|
|
@ -36,8 +36,7 @@ class MockServerContainerContextCustomizer implements ContextCustomizer {
|
|||
|
||||
@Override
|
||||
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
if (context instanceof WebApplicationContext) {
|
||||
WebApplicationContext wac = (WebApplicationContext) context;
|
||||
if (context instanceof WebApplicationContext wac) {
|
||||
ServletContext sc = wac.getServletContext();
|
||||
if (sc != null) {
|
||||
sc.setAttribute("jakarta.websocket.server.ServerContainer", new MockServerContainer());
|
||||
|
|
|
@ -45,6 +45,7 @@ abstract class AbstractMockMvcServerSpec<B extends MockMvcWebTestClient.MockMvcS
|
|||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T extends B> T filter(Filter filter, String... urlPatterns) {
|
||||
getMockMvcBuilder().addFilter(filter, urlPatterns);
|
||||
return self();
|
||||
|
|
|
@ -370,8 +370,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
});
|
||||
});
|
||||
for (NameValuePair param : this.webRequest.getRequestParameters()) {
|
||||
if (param instanceof KeyDataPair) {
|
||||
KeyDataPair pair = (KeyDataPair) param;
|
||||
if (param instanceof KeyDataPair pair) {
|
||||
File file = pair.getFile();
|
||||
MockPart part;
|
||||
if (file != null) {
|
||||
|
|
|
@ -561,11 +561,9 @@ public class MockHttpServletRequestBuilder
|
|||
if (parent == null) {
|
||||
return this;
|
||||
}
|
||||
if (!(parent instanceof MockHttpServletRequestBuilder)) {
|
||||
if (!(parent instanceof MockHttpServletRequestBuilder parentBuilder)) {
|
||||
throw new IllegalArgumentException("Cannot merge with [" + parent.getClass().getName() + "]");
|
||||
}
|
||||
MockHttpServletRequestBuilder parentBuilder = (MockHttpServletRequestBuilder) parent;
|
||||
|
||||
if (!StringUtils.hasText(this.contextPath)) {
|
||||
this.contextPath = parentBuilder.contextPath;
|
||||
}
|
||||
|
|
|
@ -122,8 +122,7 @@ public class MockMultipartHttpServletRequestBuilder extends MockHttpServletReque
|
|||
}
|
||||
if (parent instanceof MockHttpServletRequestBuilder) {
|
||||
super.merge(parent);
|
||||
if (parent instanceof MockMultipartHttpServletRequestBuilder) {
|
||||
MockMultipartHttpServletRequestBuilder parentBuilder = (MockMultipartHttpServletRequestBuilder) parent;
|
||||
if (parent instanceof MockMultipartHttpServletRequestBuilder parentBuilder) {
|
||||
this.files.addAll(parentBuilder.files);
|
||||
parentBuilder.parts.keySet().forEach(name ->
|
||||
this.parts.putIfAbsent(name, parentBuilder.parts.get(name)));
|
||||
|
|
|
@ -179,8 +179,7 @@ public class PrintingResultHandler implements ResultHandler {
|
|||
this.printer.printValue("Type", null);
|
||||
}
|
||||
else {
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
this.printer.printValue("Type", handlerMethod.getBeanType().getName());
|
||||
this.printer.printValue("Method", handlerMethod);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue