|
1 | 1 | /* |
2 | | - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -201,6 +201,23 @@ public void resolveExceptionGlobalHandlerOrdered() throws Exception { |
201 | 201 | assertEquals("TestExceptionResolver: IllegalStateException", this.response.getContentAsString()); |
202 | 202 | } |
203 | 203 |
|
| 204 | + // SPR-12605 |
| 205 | + |
| 206 | + @Test |
| 207 | + public void resolveExceptionWithHandlerMethodArg() throws Exception { |
| 208 | + AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyConfig.class); |
| 209 | + this.resolver.setApplicationContext(cxt); |
| 210 | + this.resolver.afterPropertiesSet(); |
| 211 | + |
| 212 | + ArrayIndexOutOfBoundsException ex = new ArrayIndexOutOfBoundsException(); |
| 213 | + HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle"); |
| 214 | + ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex); |
| 215 | + |
| 216 | + assertNotNull("Exception was not handled", mav); |
| 217 | + assertTrue(mav.isEmpty()); |
| 218 | + assertEquals("HandlerMethod: handle", this.response.getContentAsString()); |
| 219 | + } |
| 220 | + |
204 | 221 | @Test |
205 | 222 | public void resolveExceptionControllerAdviceHandler() throws Exception { |
206 | 223 | AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyControllerAdviceConfig.class); |
@@ -289,6 +306,12 @@ static class TestExceptionResolver { |
289 | 306 | public String handleException(IllegalStateException ex) { |
290 | 307 | return "TestExceptionResolver: " + ClassUtils.getShortName(ex.getClass()); |
291 | 308 | } |
| 309 | + |
| 310 | + @ExceptionHandler(ArrayIndexOutOfBoundsException.class) |
| 311 | + @ResponseBody |
| 312 | + public String handleWithHandlerMethod(HandlerMethod handlerMethod) { |
| 313 | + return "HandlerMethod: " + handlerMethod.getMethod().getName(); |
| 314 | + } |
292 | 315 | } |
293 | 316 |
|
294 | 317 | @ControllerAdvice |
|
0 commit comments