Merge branch '6.1.x'

This commit is contained in:
Sébastien Deleuze 2024-03-26 18:10:25 +01:00
commit 96d9081190
21 changed files with 39 additions and 10 deletions

View File

@ -97,6 +97,7 @@ public class MockFilterConfig implements FilterConfig {
} }
@Override @Override
@Nullable
public String getInitParameter(String name) { public String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null"); Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name); return this.initParameters.get(name);

View File

@ -383,6 +383,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@Override @Override
@Nullable
public Object getAttribute(String name) { public Object getAttribute(String name) {
checkActive(); checkActive();
return this.attributes.get(name); return this.attributes.get(name);
@ -637,6 +638,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
} }
@Override @Override
@Nullable
public String[] getParameterValues(String name) { public String[] getParameterValues(String name) {
Assert.notNull(name, "Parameter name must not be null"); Assert.notNull(name, "Parameter name must not be null");
return this.parameters.get(name); return this.parameters.get(name);

View File

@ -148,6 +148,7 @@ public class MockHttpSession implements HttpSession {
} }
@Override @Override
@Nullable
public Object getAttribute(String name) { public Object getAttribute(String name) {
assertIsValid(); assertIsValid();
Assert.notNull(name, "Attribute name must not be null"); Assert.notNull(name, "Attribute name must not be null");

View File

@ -96,6 +96,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
} }
@Override @Override
@Nullable
public MultipartFile getFile(String name) { public MultipartFile getFile(String name) {
return this.multipartFiles.getFirst(name); return this.multipartFiles.getFirst(name);
} }
@ -117,6 +118,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
} }
@Override @Override
@Nullable
public String getMultipartContentType(String paramOrFileName) { public String getMultipartContentType(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName); MultipartFile file = getFile(paramOrFileName);
if (file != null) { if (file != null) {
@ -154,6 +156,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
} }
@Override @Override
@Nullable
public HttpHeaders getMultipartHeaders(String paramOrFileName) { public HttpHeaders getMultipartHeaders(String paramOrFileName) {
MultipartFile file = getFile(paramOrFileName); MultipartFile file = getFile(paramOrFileName);
if (file != null) { if (file != null) {

View File

@ -93,6 +93,7 @@ public class MockServletConfig implements ServletConfig {
} }
@Override @Override
@Nullable
public String getInitParameter(String name) { public String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null"); Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name); return this.initParameters.get(name);

View File

@ -224,6 +224,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public ServletContext getContext(String contextPath) { public ServletContext getContext(String contextPath) {
if (this.contextPath.equals(contextPath)) { if (this.contextPath.equals(contextPath)) {
return this; return this;
@ -376,6 +377,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public RequestDispatcher getNamedDispatcher(String path) { public RequestDispatcher getNamedDispatcher(String path) {
return this.namedRequestDispatchers.get(path); return this.namedRequestDispatchers.get(path);
} }
@ -465,6 +467,7 @@ public class MockServletContext implements ServletContext {
} }
@Override @Override
@Nullable
public String getInitParameter(String name) { public String getInitParameter(String name) {
Assert.notNull(name, "Parameter name must not be null"); Assert.notNull(name, "Parameter name must not be null");
return this.initParameters.get(name); return this.initParameters.get(name);

View File

@ -136,6 +136,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig {
} }
@Override @Override
@Nullable
public String getAttribute(String name) { public String getAttribute(String name) {
return this.attributes.get(name); return this.attributes.get(name);
} }

View File

@ -569,6 +569,7 @@ public final class MockServerRequest implements ServerRequest {
} }
@Override @Override
@Nullable
public InetSocketAddress host() { public InetSocketAddress host() {
return delegate().getHost(); return delegate().getHost();
} }

View File

@ -17,6 +17,7 @@
package org.springframework.test.context; package org.springframework.test.context;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
/** /**
* Strategy for components that process failures related to application contexts * Strategy for components that process failures related to application contexts
@ -41,6 +42,6 @@ public interface ApplicationContextFailureProcessor {
* @param context the application context that did not load successfully * @param context the application context that did not load successfully
* @param exception the exception thrown while loading the application context * @param exception the exception thrown while loading the application context
*/ */
void processLoadFailure(ApplicationContext context, Throwable exception); void processLoadFailure(ApplicationContext context, @Nullable Throwable exception);
} }

View File

@ -17,7 +17,6 @@
package org.springframework.test.context; package org.springframework.test.context;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
/** /**
* Strategy interface for loading an {@link ApplicationContext} for an integration * Strategy interface for loading an {@link ApplicationContext} for an integration
@ -157,7 +156,7 @@ public interface SmartContextLoader extends ContextLoader {
*/ */
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
default String[] processLocations(Class<?> clazz, @Nullable String... locations) { default String[] processLocations(Class<?> clazz, String... locations) {
throw new UnsupportedOperationException(""" throw new UnsupportedOperationException("""
SmartContextLoader does not support the ContextLoader SPI. \ SmartContextLoader does not support the ContextLoader SPI. \
Call processContextConfiguration(ContextConfigurationAttributes) instead."""); Call processContextConfiguration(ContextConfigurationAttributes) instead.""");

View File

@ -26,6 +26,7 @@ import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeHint;
import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
@ -39,7 +40,7 @@ import org.springframework.util.ClassUtils;
class TestContextRuntimeHints implements RuntimeHintsRegistrar { class TestContextRuntimeHints implements RuntimeHintsRegistrar {
@Override @Override
public void registerHints(RuntimeHints runtimeHints, ClassLoader classLoader) { public void registerHints(RuntimeHints runtimeHints, @Nullable ClassLoader classLoader) {
boolean servletPresent = ClassUtils.isPresent("jakarta.servlet.Servlet", classLoader); boolean servletPresent = ClassUtils.isPresent("jakarta.servlet.Servlet", classLoader);
boolean groovyPresent = ClassUtils.isPresent("groovy.lang.Closure", classLoader); boolean groovyPresent = ClassUtils.isPresent("groovy.lang.Closure", classLoader);

View File

@ -20,6 +20,7 @@ import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.lang.Nullable;
import org.springframework.util.function.SupplierUtils; import org.springframework.util.function.SupplierUtils;
/** /**
@ -38,6 +39,7 @@ class DynamicValuesPropertySource extends MapPropertySource {
} }
@Override @Override
@Nullable
public Object getProperty(String name) { public Object getProperty(String name) {
return SupplierUtils.resolve(super.getProperty(name)); return SupplierUtils.resolve(super.getProperty(name));
} }

View File

@ -459,6 +459,7 @@ public abstract class TestPropertySourceUtils {
private final LinkedHashMap<String, Object> map = new LinkedHashMap<>(); private final LinkedHashMap<String, Object> map = new LinkedHashMap<>();
@Override @Override
@Nullable
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
if (key instanceof String str) { if (key instanceof String str) {
return this.map.put(str, value); return this.map.put(str, value);

View File

@ -198,6 +198,7 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App
} }
@Nullable
private Throwable getTestResultException(ITestResult testResult) { private Throwable getTestResultException(ITestResult testResult) {
Throwable testResultException = testResult.getThrowable(); Throwable testResultException = testResult.getThrowable();
if (testResultException instanceof InvocationTargetException) { if (testResultException instanceof InvocationTargetException) {

View File

@ -155,6 +155,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false) { protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false) {
@Override @Override
@Nullable
protected TransactionAttribute findTransactionAttribute(Class<?> clazz) { protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
// @Transactional present in inheritance hierarchy? // @Transactional present in inheritance hierarchy?
TransactionAttribute result = super.findTransactionAttribute(clazz); TransactionAttribute result = super.findTransactionAttribute(clazz);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.mock.http.client.MockClientHttpRequest;
import org.springframework.test.web.client.ResponseCreator; import org.springframework.test.web.client.ResponseCreator;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -59,7 +60,7 @@ public class ExecutingResponseCreator implements ResponseCreator {
@Override @Override
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException { public ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException {
Assert.state(request instanceof MockClientHttpRequest, "Expected a MockClientHttpRequest"); Assert.state(request instanceof MockClientHttpRequest, "Expected a MockClientHttpRequest");
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request; MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
ClientHttpRequest newRequest = this.requestFactory.createRequest(mockRequest.getURI(), mockRequest.getMethod()); ClientHttpRequest newRequest = this.requestFactory.createRequest(mockRequest.getURI(), mockRequest.getMethod());

View File

@ -127,7 +127,7 @@ class DefaultMvcResult implements MvcResult {
return RequestContextUtils.getOutputFlashMap(this.mockRequest); return RequestContextUtils.getOutputFlashMap(this.mockRequest);
} }
public void setAsyncResult(Object asyncResult) { public void setAsyncResult(@Nullable Object asyncResult) {
this.asyncResult.set(asyncResult); this.asyncResult.set(asyncResult);
} }

View File

@ -98,7 +98,7 @@ final class TestDispatcherServlet extends DispatcherServlet {
WebAsyncUtils.getAsyncManager(request).registerCallableInterceptor(KEY, WebAsyncUtils.getAsyncManager(request).registerCallableInterceptor(KEY,
new CallableProcessingInterceptor() { new CallableProcessingInterceptor() {
@Override @Override
public <T> void postProcess(NativeWebRequest r, Callable<T> task, Object value) { public <T> void postProcess(NativeWebRequest r, Callable<T> task, @Nullable Object value) {
// We got the result, must also wait for the dispatch // We got the result, must also wait for the dispatch
getMvcResult(request).setAsyncResult(value); getMvcResult(request).setAsyncResult(value);
} }
@ -107,7 +107,7 @@ final class TestDispatcherServlet extends DispatcherServlet {
WebAsyncUtils.getAsyncManager(request).registerDeferredResultInterceptor(KEY, WebAsyncUtils.getAsyncManager(request).registerDeferredResultInterceptor(KEY,
new DeferredResultProcessingInterceptor() { new DeferredResultProcessingInterceptor() {
@Override @Override
public <T> void postProcess(NativeWebRequest r, DeferredResult<T> result, Object value) { public <T> void postProcess(NativeWebRequest r, DeferredResult<T> result, @Nullable Object value) {
getMvcResult(request).setAsyncResult(value); getMvcResult(request).setAsyncResult(value);
} }
}); });
@ -118,6 +118,7 @@ final class TestDispatcherServlet extends DispatcherServlet {
} }
@Override @Override
@Nullable
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
HandlerExecutionChain chain = super.getHandler(request); HandlerExecutionChain chain = super.getHandler(request);
if (chain != null) { if (chain != null) {
@ -138,6 +139,7 @@ final class TestDispatcherServlet extends DispatcherServlet {
} }
@Override @Override
@Nullable
protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response,
@Nullable Object handler, Exception ex) throws Exception { @Nullable Object handler, Exception ex) throws Exception {

View File

@ -451,6 +451,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
} }
@Override @Override
@Nullable
public HttpSession getSession(boolean create) { public HttpSession getSession(boolean create) {
HttpSession session = super.getSession(false); HttpSession session = super.getSession(false);
if (session == null && create) { if (session == null && create) {

View File

@ -130,6 +130,7 @@ class StubWebApplicationContext implements WebApplicationContext {
} }
@Override @Override
@Nullable
public ApplicationContext getParent() { public ApplicationContext getParent() {
return null; return null;
} }
@ -218,11 +219,13 @@ class StubWebApplicationContext implements WebApplicationContext {
} }
@Override @Override
@Nullable
public Class<?> getType(String name) throws NoSuchBeanDefinitionException { public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
return this.beanFactory.getType(name); return this.beanFactory.getType(name);
} }
@Override @Override
@Nullable
public Class<?> getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { public Class<?> getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException {
return this.beanFactory.getType(name, allowFactoryBeanInit); return this.beanFactory.getType(name, allowFactoryBeanInit);
} }
@ -337,6 +340,7 @@ class StubWebApplicationContext implements WebApplicationContext {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@Override @Override
@Nullable
public BeanFactory getParentBeanFactory() { public BeanFactory getParentBeanFactory() {
return null; return null;
} }
@ -352,6 +356,7 @@ class StubWebApplicationContext implements WebApplicationContext {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@Override @Override
@Nullable
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) { public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
return this.messageSource.getMessage(code, args, defaultMessage, locale); return this.messageSource.getMessage(code, args, defaultMessage, locale);
} }

View File

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.test.context.ApplicationContextFailureProcessor; import org.springframework.test.context.ApplicationContextFailureProcessor;
/** /**
@ -37,10 +38,10 @@ public class TrackingApplicationContextFailureProcessor implements ApplicationCo
@Override @Override
public void processLoadFailure(ApplicationContext context, Throwable exception) { public void processLoadFailure(ApplicationContext context, @Nullable Throwable exception) {
loadFailures.add(new LoadFailure(context, exception)); loadFailures.add(new LoadFailure(context, exception));
} }
public record LoadFailure(ApplicationContext context, Throwable exception) {} public record LoadFailure(ApplicationContext context, @Nullable Throwable exception) {}
} }