ResettableStreamHttpServletRequest extends HttpServletRequestWrapper { @Override public BufferedReader getReader() throws IOException { if (rawData == null) { rawData = IOUtils.toByteArray(this.request.getReader()); servletStream.stream = new ByteArrayInputStream(rawData); } return new BufferedReader(new InputStreamReader(servletStream)); } ResettableStreamHttpServletRequest(final HttpServletRequest request); void resetInputStream(); @Override ServletInputStream getInputStream(); @Override BufferedReader getReader(); void setRawData(final byte[] rawData);  }
@Test public void testGetReader() throws Exception { String message = "message"; ResettableStreamHttpServletRequest unit = new ResettableStreamHttpServletRequest(request); InputStream is = new ByteArrayInputStream(message.getBytes()); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); when(request.getReader()).thenReturn(reader); unit.setRawData(message.getBytes()); Reader actual = unit.getReader(); assertNotNull(actual); }