SystemExceptionResolver extends SimpleMappingExceptionResolver { protected void setResultMessages(Exception ex, HttpServletRequest request) { if (!StringUtils.hasText(resultMessagesAttribute)) { return; } if (!(ex instanceof ResultMessagesNotificationException)) { return; } ResultMessages resultMessages = ((ResultMessagesNotificationException) ex) .getResultMessages(); request.setAttribute(resultMessagesAttribute, resultMessages); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (flashMap != null) { flashMap.put(resultMessagesAttribute, resultMessages); } }  void setExceptionCodeAttribute(String exceptionCodeAttribute); void setExceptionCodeHeader(String exceptionCodeHeader); void setResultMessagesAttribute(String resultMessagesAttribute); void setExceptionCodeResolver(
            ExceptionCodeResolver exceptionCodeResolver);  }
@Test public void testSetResultMessages_BusinessException_flashMap_is_null() { ResultMessages resultMessages = ResultMessages.error().add("code01"); BusinessException occurException = new BusinessException(resultMessages); testTarget.setResultMessages(occurException, mockRequest); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(mockRequest); assertThat(flashMap, is(nullValue())); }
@Test public void testSetResultMessages_BusinessException_flashMap_is_notnull() { FlashMap flashMap = new FlashMap(); mockRequest.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap); ResultMessages resultMessages = ResultMessages.error().add("code01"); BusinessException occurException = new BusinessException(resultMessages); testTarget.setResultMessages(occurException, mockRequest); assertThat(resultMessages, is(flashMap.get( ResultMessages.DEFAULT_MESSAGES_ATTRIBUTE_NAME))); }
@Test public void testSetResultMessages_not_BusinessException() { FlashMap flashMap = new FlashMap(); mockRequest.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap); SystemException occurException = new SystemException("code01", "message"); testTarget.setResultMessages(occurException, mockRequest); assertThat(flashMap.isEmpty(), is(true)); }