### Question:
SpringViewResolverProvider extends AbstractResponseViewProvider { public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { View view = getView(clazz, o); String attributeName = getBeanName(o); Map<String, Object> model = Collections.singletonMap(attributeName, o); try { getMessageContext().put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE); logRedirection(view, attributeName, o); view.render(model, getMessageContext().getHttpServletRequest(), getMessageContext().getHttpServletResponse()); } catch (Throwable ex) { handleViewRenderingException(view.toString(), ex); } } SpringViewResolverProvider(ViewResolver viewResolver, LocaleResolver localeResolver); void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType type,
            MultivaluedMap<String, Object> headers, OutputStream os);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testWriteTo() throws Exception { String viewName = "/test"; expectWriteTo(viewName); viewMock.render(anyObject(Map.class), anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall(); replayAll(); viewResolver.writeTo(TestEnum.ONE, TestEnum.ONE.getClass(), null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, new MultivaluedHashMap<String, Object>(), null); }
@SuppressWarnings("unchecked") @Test public void testWriteToWithRenderingError() throws Exception { String viewName = "/test"; Exception exception = new RuntimeException("my exception"); expectWriteTo(viewName); viewMock.render(anyObject(Map.class), anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall().andThrow(exception); requestMock.setAttribute(RequestDispatcher.ERROR_EXCEPTION, exception); requestMock.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, 500); requestMock.setAttribute(RequestDispatcher.ERROR_MESSAGE, exception.getMessage()); expect(servletContextMock.getRequestDispatcher("/error")).andReturn(requestDispatcherMock); requestDispatcherMock.forward(anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall(); replayAll(); viewResolver.writeTo(TestEnum.ONE, TestEnum.ONE.getClass(), null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, new MultivaluedHashMap<String, Object>(), null); }
@SuppressWarnings("unchecked") @Test(expected = InternalServerErrorException.class) public void testWriteToWithInternalRenderingError() throws Exception { String viewName = "/test"; Exception exception = new RuntimeException("my exception"); expectWriteTo(viewName); viewMock.render(anyObject(Map.class), anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall().andThrow(exception); requestMock.setAttribute(RequestDispatcher.ERROR_EXCEPTION, exception); requestMock.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, 500); requestMock.setAttribute(RequestDispatcher.ERROR_MESSAGE, exception.getMessage()); expect(servletContextMock.getRequestDispatcher("/error")).andReturn(requestDispatcherMock); requestDispatcherMock.forward(anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall().andThrow(new RuntimeException("internal")); replayAll(); viewResolver.writeTo(TestEnum.ONE, TestEnum.ONE.getClass(), null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, new MultivaluedHashMap<String, Object>(), null); }
@SuppressWarnings("unchecked") @Test(expected = InternalServerErrorException.class) public void testWriteToWithNullErrorView() throws Exception { viewResolver.setErrorView(null); String viewName = "/test"; Exception exception = new RuntimeException("my exception"); expectWriteTo(viewName); viewMock.render(anyObject(Map.class), anyObject(HttpServletRequest.class), anyObject(HttpServletResponse.class)); expectLastCall().andThrow(exception); replayAll(); viewResolver.writeTo(TestEnum.ONE, TestEnum.ONE.getClass(), null, new Annotation[] {}, MediaType.TEXT_HTML_TYPE, new MultivaluedHashMap<String, Object>(), null); }