From 19b4021d26867b5bcee70d372bf250bdd5f7ffda Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Fri, 10 Oct 2025 18:45:20 +0200 Subject: [PATCH] Polish tests --- .../ExceptionHandlerMethodResolverTests.java | 19 ++++++------------- ...xceptionHandlerExceptionResolverTests.java | 2 +- .../ResponseEntityExceptionHandlerTests.java | 7 +++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java index a99eb76ced0..d8db3ce32b2 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java @@ -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() { - } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java index ea11e20c51c..0f61a24734b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java @@ -544,7 +544,7 @@ class ExceptionHandlerExceptionResolverTests { public void handle() {} - @ExceptionHandler(value = IOException.class) + @ExceptionHandler(IOException.class) public void handleException() { } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java index 46bc91fd61c..e3a310e5b79 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java @@ -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) exceptionType)); + .contains(exceptionType)); } @Test