Browse Source

Polish tests

pull/35599/head
Sam Brannen 2 months ago
parent
commit
19b4021d26
  1. 19
      spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java
  2. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java
  3. 7
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java

19
spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java

@ -208,14 +208,12 @@ class ExceptionHandlerMethodResolverTests { @@ -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 { @@ -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 { @@ -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 { @@ -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() {
}
}

2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java

@ -544,7 +544,7 @@ class ExceptionHandlerExceptionResolverTests { @@ -544,7 +544,7 @@ class ExceptionHandlerExceptionResolverTests {
public void handle() {}
@ExceptionHandler(value = IOException.class)
@ExceptionHandler(IOException.class)
public void handleException() {
}
}

7
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java

@ -97,22 +97,21 @@ class ResponseEntityExceptionHandlerTests { @@ -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

Loading…
Cancel
Save