@Test public void defaultErrorViewDifferentHandler() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); assertNull(mav); }
@Test public void simpleExceptionMappingWithHandlerSpecifiedButWrongHandler() { Properties props = new Properties(); props.setProperty("Exception", "error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); assertNull(mav); }
@Test public void exactExceptionMappingWithHandlerSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); assertEquals("error", mav.getViewName()); }
@Test public void twoMappingsOneShortOneLong() { Properties props = new Properties(); props.setProperty("Exception", "error"); props.setProperty("AnotherException", "another-error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); assertEquals("error", mav.getViewName()); }
@Test public void twoMappingsThrowOddExceptionUseLongExceptionMapping() { Exception oddException = new SomeOddException(); Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); props.setProperty("SomeOddException", "another-error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); exceptionResolver.setExceptionMappings(props); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, oddException); assertEquals("another-error", mav.getViewName()); }