mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
Polish tests
This commit is contained in:
+6
-13
@@ -208,14 +208,12 @@ class ExceptionHandlerMethodResolverTests {
|
||||
@Controller
|
||||
static class MediaTypeController {
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
|
||||
public void handleJson() {
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = {"text/html", "*/*"})
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = {"text/html", "*/*"})
|
||||
public void handleHtml() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -223,14 +221,12 @@ class ExceptionHandlerMethodResolverTests {
|
||||
@Controller
|
||||
static class AmbiguousMediaTypeController {
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
|
||||
public void handleJson() {
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
|
||||
public void handleJsonToo() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -238,14 +234,12 @@ class ExceptionHandlerMethodResolverTests {
|
||||
@Controller
|
||||
static class MixedController {
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
|
||||
public void handleJson() {
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public void handleOther() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -253,9 +247,8 @@ class ExceptionHandlerMethodResolverTests {
|
||||
@Controller
|
||||
static class InvalidMediaTypeController {
|
||||
|
||||
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "invalid-mediatype")
|
||||
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "invalid-mediatype")
|
||||
public void handle() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -544,7 +544,7 @@ class ExceptionHandlerExceptionResolverTests {
|
||||
|
||||
public void handle() {}
|
||||
|
||||
@ExceptionHandler(value = IOException.class)
|
||||
@ExceptionHandler(IOException.class)
|
||||
public void handleException() {
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -97,22 +97,21 @@ class ResponseEntityExceptionHandlerTests {
|
||||
private WebRequest request = new ServletWebRequest(this.servletRequest, this.servletResponse);
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {
|
||||
|
||||
ExceptionHandler annotation = ResponseEntityExceptionHandler.class
|
||||
.getMethod("handleException", Exception.class, WebRequest.class)
|
||||
.getAnnotation(ExceptionHandler.class);
|
||||
Class<?>[] exceptionTypes = annotation.value();
|
||||
|
||||
Arrays.stream(DefaultHandlerExceptionResolver.class.getDeclaredMethods())
|
||||
.filter(method -> method.getName().startsWith("handle") && (method.getParameterCount() == 4))
|
||||
.filter(method -> !method.getName().equals("handleErrorResponse"))
|
||||
.filter(method -> !method.getName().equals("handleDisconnectedClientException"))
|
||||
.map(method -> method.getParameterTypes()[0])
|
||||
.forEach(exceptionType -> assertThat(annotation.value())
|
||||
.forEach(exceptionType -> assertThat(exceptionTypes)
|
||||
.as("@ExceptionHandler is missing declaration for " + exceptionType.getName())
|
||||
.contains((Class<Exception>) exceptionType));
|
||||
.contains(exceptionType));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user