@MessageExceptionHandler matches cause as well (analogous to @ExceptionHandler)

Issue: SPR-14424
This commit is contained in:
Juergen Hoeller
2016-07-02 12:56:37 +02:00
parent cfc560c4c4
commit e5de7d5455
2 changed files with 43 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import static org.junit.Assert.*;
* Test fixture for {@link AnnotationExceptionHandlerMethodResolver} tests.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
*/
public class AnnotationExceptionHandlerMethodResolverTests {
@@ -50,6 +51,13 @@ public class AnnotationExceptionHandlerMethodResolverTests {
assertEquals("handleIllegalArgumentException", resolver.resolveMethod(exception).getName());
}
@Test
public void resolveMethodFromArgumentWithErrorType() {
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(ExceptionController.class);
AssertionError exception = new AssertionError();
assertEquals("handleAssertionError", resolver.resolveMethod(new IllegalStateException(exception)).getName());
}
@Test
public void resolveMethodExceptionSubType() {
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(ExceptionController.class);
@@ -91,6 +99,7 @@ public class AnnotationExceptionHandlerMethodResolverTests {
new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class);
}
@Controller
static class ExceptionController {
@@ -107,8 +116,13 @@ public class AnnotationExceptionHandlerMethodResolverTests {
@MessageExceptionHandler
public void handleIllegalArgumentException(IllegalArgumentException exception) {
}
@MessageExceptionHandler
public void handleAssertionError(AssertionError exception) {
}
}
@Controller
static class InheritedController extends ExceptionController {
@@ -117,6 +131,7 @@ public class AnnotationExceptionHandlerMethodResolverTests {
}
}
@Controller
static class AmbiguousController {
@@ -133,6 +148,7 @@ public class AnnotationExceptionHandlerMethodResolverTests {
}
}
@Controller
static class NoExceptionController {