Skip to content

Commit 19b4021

Browse files
committed
Polish tests
1 parent e21fa38 commit 19b4021

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,54 +208,47 @@ public void handle() {
208208
@Controller
209209
static class MediaTypeController {
210210

211-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
211+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
212212
public void handleJson() {
213-
214213
}
215214

216-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = {"text/html", "*/*"})
215+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = {"text/html", "*/*"})
217216
public void handleHtml() {
218-
219217
}
220218

221219
}
222220

223221
@Controller
224222
static class AmbiguousMediaTypeController {
225223

226-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
224+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
227225
public void handleJson() {
228-
229226
}
230227

231-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
228+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
232229
public void handleJsonToo() {
233-
234230
}
235231

236232
}
237233

238234
@Controller
239235
static class MixedController {
240236

241-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "application/json")
237+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "application/json")
242238
public void handleJson() {
243-
244239
}
245240

246241
@ExceptionHandler(IllegalArgumentException.class)
247242
public void handleOther() {
248-
249243
}
250244

251245
}
252246

253247
@Controller
254248
static class InvalidMediaTypeController {
255249

256-
@ExceptionHandler(exception = {IllegalArgumentException.class}, produces = "invalid-mediatype")
250+
@ExceptionHandler(exception = IllegalArgumentException.class, produces = "invalid-mediatype")
257251
public void handle() {
258-
259252
}
260253
}
261254

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static class IoExceptionController {
544544

545545
public void handle() {}
546546

547-
@ExceptionHandler(value = IOException.class)
547+
@ExceptionHandler(IOException.class)
548548
public void handleException() {
549549
}
550550
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,21 @@ class ResponseEntityExceptionHandlerTests {
9797
private WebRequest request = new ServletWebRequest(this.servletRequest, this.servletResponse);
9898

9999

100-
@SuppressWarnings("unchecked")
101100
@Test
102101
void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {
103-
104102
ExceptionHandler annotation = ResponseEntityExceptionHandler.class
105103
.getMethod("handleException", Exception.class, WebRequest.class)
106104
.getAnnotation(ExceptionHandler.class);
105+
Class<?>[] exceptionTypes = annotation.value();
107106

108107
Arrays.stream(DefaultHandlerExceptionResolver.class.getDeclaredMethods())
109108
.filter(method -> method.getName().startsWith("handle") && (method.getParameterCount() == 4))
110109
.filter(method -> !method.getName().equals("handleErrorResponse"))
111110
.filter(method -> !method.getName().equals("handleDisconnectedClientException"))
112111
.map(method -> method.getParameterTypes()[0])
113-
.forEach(exceptionType -> assertThat(annotation.value())
112+
.forEach(exceptionType -> assertThat(exceptionTypes)
114113
.as("@ExceptionHandler is missing declaration for " + exceptionType.getName())
115-
.contains((Class<Exception>) exceptionType));
114+
.contains(exceptionType));
116115
}
117116

118117
@Test

0 commit comments

Comments
 (0)