ResettableStreamHttpServletRequest extends HttpServletRequestWrapper { @Override public ServletInputStream getInputStream() throws IOException { if (rawData == null) { rawData = IOUtils.toByteArray(this.request.getReader()); servletStream.stream = new ByteArrayInputStream(rawData); } return servletStream; } ResettableStreamHttpServletRequest(final HttpServletRequest request); void resetInputStream(); @Override ServletInputStream getInputStream(); @Override BufferedReader getReader(); void setRawData(final byte[] rawData);  }
@Test public void testGetInputStream() 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()); ServletInputStream actual = unit.getInputStream(); assertNotNull(actual); }