/** * Converts an inputStream to a String with Apache Commons' IOUtils. * @param inputStream InputStream to convert * @return converted stream * @throws ApplicationException when IOUtils or mark/reset fails */ 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; } }
@Test public void testExtractShouldDoNothingWhenExceptionIsThrown() throws Exception { doThrow(new ApplicationException("")).when(base64DecoderProcessor).process(message); underTest.extract(message); } }
@Test public void testProcessShouldLogErrorWhenRequestTransformerThrowsApplicationException() throws ApplicationException { // GIVEN ApplicationException e = new ApplicationException(EMPTY_STRING); given(httpRequestTransformer.transformRequest(bmRequest)).willThrow(e); // WHEN underTest.process(bmRequest); // THEN verify(logger).error(EMPTY_STRING, e); }
@Test public void testProcessWhenApplicationExceptionIsThrownShouldLogError() throws ApplicationException { // GIVEN ApplicationException e = new ApplicationException("exception"); given(responseTransformer.transformResponse(response)).willReturn(wilmaResponse); BDDMockito.willThrow(e).given(responseHandler).processResponse(wilmaResponse); // WHEN underTest.process(response); // THEN verify(logger).error("exception", e); }
@Test public void testProcessShouldLogErrorWhenHandleRequestThrowsApplicationException() throws ApplicationException { // GIVEN ApplicationException e = new ApplicationException(EMPTY_STRING); given(httpRequestTransformer.transformRequest(bmRequest)).willReturn(wilmaRequest); willThrow(e).given(wilmaHttpRequestHandler).processRequest(wilmaRequest); // WHEN underTest.process(bmRequest); // THEN verify(logger).error(EMPTY_STRING, e); }