WebXmlEncodingHandler implements EncodingHandler { public void setEncoding(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); } catch (UnsupportedEncodingException e) { throw new VRaptorException(e); } } WebXmlEncodingHandler(String encoding); void setEncoding(HttpServletRequest request, HttpServletResponse response);  }
@Test public void shouldSetEncodingToUTF8() throws Exception { when(context.getInitParameter(ENCODING)).thenReturn("UTF-8"); new WebXmlEncodingHandler("UTF-8").setEncoding(request, response); verify(request).setCharacterEncoding("UTF-8"); verify(response).setCharacterEncoding("UTF-8"); }
@Test(expected=VRaptorException.class) public void shouldThrowExceptionWhenAnUnsupportedEncodingExceptionOccurs() throws Exception { doThrow(new UnsupportedEncodingException()).when(request).setCharacterEncoding(anyString()); new WebXmlEncodingHandler("UTF-8").setEncoding(request, response); }