|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.util.Arrays;
|
21 | 21 | import java.util.Collections;
|
22 | 22 |
|
| 23 | +import jakarta.servlet.http.HttpServletRequest; |
| 24 | +import jakarta.servlet.http.HttpServletResponse; |
23 | 25 | import org.junit.jupiter.api.BeforeEach;
|
24 | 26 | import org.junit.jupiter.api.Test;
|
25 | 27 |
|
|
32 | 34 | import org.springframework.http.converter.HttpMessageNotReadableException;
|
33 | 35 | import org.springframework.http.converter.HttpMessageNotWritableException;
|
34 | 36 | import org.springframework.http.server.ServletServerHttpRequest;
|
| 37 | +import org.springframework.lang.Nullable; |
35 | 38 | import org.springframework.validation.BeanPropertyBindingResult;
|
36 | 39 | import org.springframework.validation.BindException;
|
37 | 40 | import org.springframework.web.HttpMediaTypeNotSupportedException;
|
|
42 | 45 | import org.springframework.web.bind.ServletRequestBindingException;
|
43 | 46 | import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
|
44 | 47 | import org.springframework.web.multipart.support.MissingServletRequestPartException;
|
| 48 | +import org.springframework.web.servlet.HandlerExceptionResolver; |
45 | 49 | import org.springframework.web.servlet.ModelAndView;
|
46 | 50 | import org.springframework.web.servlet.NoHandlerFoundException;
|
47 | 51 | import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
@@ -232,6 +236,27 @@ public void handleAsyncRequestTimeoutException() throws Exception {
|
232 | 236 | assertThat(response.getStatus()).as("Invalid status code").isEqualTo(503);
|
233 | 237 | }
|
234 | 238 |
|
| 239 | + @Test |
| 240 | + public void customModelAndView() { |
| 241 | + ModelAndView expected = new ModelAndView(); |
| 242 | + |
| 243 | + HandlerExceptionResolver resolver = new DefaultHandlerExceptionResolver() { |
| 244 | + |
| 245 | + @Override |
| 246 | + protected ModelAndView handleHttpRequestMethodNotSupported( |
| 247 | + HttpRequestMethodNotSupportedException ex, HttpServletRequest request, |
| 248 | + HttpServletResponse response, @Nullable Object handler) { |
| 249 | + |
| 250 | + return expected; |
| 251 | + } |
| 252 | + }; |
| 253 | + |
| 254 | + HttpRequestMethodNotSupportedException ex = new HttpRequestMethodNotSupportedException("GET"); |
| 255 | + |
| 256 | + ModelAndView actual = resolver.resolveException(request, response, null, ex); |
| 257 | + assertThat(actual).isSameAs(expected); |
| 258 | + } |
| 259 | + |
235 | 260 |
|
236 | 261 | @SuppressWarnings("unused")
|
237 | 262 | public void handle(String arg) {
|
|
0 commit comments