@Override public void writeTo(OutputStream os) throws IOException { try { if (writeBodyContentOnly) { Body body = bodyPart.getBody(); InputStream inputStream = body.getInputStream(); IOUtils.copy(inputStream, os); } else { bodyPart.writeTo(os); } } catch (MessagingException e) { throw new IOException(e); } } };
inputStream = body.getInputStream();
@Test public void getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull() throws Exception { part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html"); Body body = mock(Body.class); when(body.getInputStream()).thenThrow(new MessagingException("Test")); part.setBody(body); String result = MessageExtractor.getTextFromPart(part); assertNull(result); }