InputStreamConverter { public String getStringFromStream(final InputStream inputStream) throws ApplicationException { String result = ""; if (inputStream != null) { try { int extendedReadLimit = inputStream.available() + BUFFER_SIZE; inputStream.mark(extendedReadLimit); result = IOUtils.toString(inputStream); inputStream.reset(); } catch (IOException e) { throw new ApplicationException("Could not transform request input stream into string!", e); } } return result; }  String getStringFromStream(final InputStream inputStream);  }
@Test public void testGetStringFromStreamShouldReturnCorrectString() throws ApplicationException { String s = TEST; byte[] buffer = s.getBytes(); inputStream = new ByteArrayInputStream(buffer); String actual = underTest.getStringFromStream(inputStream); Assert.assertEquals(actual, TEST); }
@Test public void testGetStringFromStreamShouldReturnEmptyStringWhenInputStreamIsNull() throws ApplicationException { inputStream = null; String actual = underTest.getStringFromStream(inputStream); Assert.assertEquals(actual, ""); }
@Test(expectedExceptions = ApplicationException.class) public void testGetStringFromStreamShouldThrowApplicationException() throws ApplicationException, IOException { given(inputStreamMock.available()).willThrow(new IOException()); underTest.getStringFromStream(inputStreamMock); }