### Question:
EmailViewPartsFetcherImpl implements EmailViewPartsFetcher { @VisibleForTesting InputStream fetchBodyData(FetchInstruction fetchInstruction, long uid) throws MailException, EmailViewPartsFetcherException { InputStream bodyData = null; try { if (fetchInstruction.hasMimePartAddressDefined()) { MimeAddress address = fetchInstruction.getMimePart().getAddress(); Integer truncation = fetchInstruction.getTruncation(); if (truncation != null) { bodyData = mailboxService.fetchPartialMimePartStream(udr, path, uid, address, truncation); } else { bodyData = mailboxService.fetchMimePartStream(udr, path, uid, address); } if (bodyData != null) { return new ByteArrayInputStream(ByteStreams.toByteArray(bodyData)); } throw new EmailViewPartsFetcherException(String.format( "Cannot fetch bodyData for collectionPath:%s, uid:%d, address:%s, truncation:%b", path, uid, address, truncation!=null)); } else { return mailboxService.fetchMailStream(udr, path, uid, getTruncation(fetchInstruction)); } } catch (IOException e) { throw new MailException(e); } finally { IOUtils.closeQuietly(bodyData); } } EmailViewPartsFetcherImpl(TransformersFactory transformersFactory, MailboxService mailboxService, 
			List<BodyPreference> bodyPreferences, UserDataRequest udr, MailboxPath path, CollectionId collectionId); @Override EmailView fetch(long uid, BodyPreferencePolicy bodyPreferencePolicy); @Override ICalendar fetchInvitation(long uid);  }### Answer:
@Test public void fetchBodyDataShouldNotTruncateWhenNoMimePartAddressAndNoTruncation() throws Exception { MimePart message = control.createMock(MimePart.class); expect(message.getAddress()) .andReturn(null); FetchInstruction fetchInstruction = FetchInstruction.builder() .mimePart(message) .build(); MailboxService mailboxService = control.createMock(MailboxService.class); EmailViewPartsFetcherImpl emailViewPartsFetcherImpl = newFetcherFromExpectedFixture(mailboxService); expect(mailboxService.fetchMailStream(udr, messageCollectionPath, messageFixture.uid, Optional.<Long> absent())) .andReturn(control.createMock(InputStream.class)); control.replay(); emailViewPartsFetcherImpl.fetchBodyData(fetchInstruction, 1); control.verify(); }
@Test public void fetchBodyDataShouldTruncateWhenNoMimePartAddressAndTruncation() throws Exception { MimePart message = control.createMock(MimePart.class); expect(message.getAddress()) .andReturn(null); int truncation = 20000; FetchInstruction fetchInstruction = FetchInstruction.builder() .mimePart(message) .truncation(truncation) .build(); MailboxService mailboxService = control.createMock(MailboxService.class); EmailViewPartsFetcherImpl emailViewPartsFetcherImpl = newFetcherFromExpectedFixture(mailboxService); expect(mailboxService.fetchMailStream(udr, messageCollectionPath, messageFixture.uid, Optional.of(Long.valueOf(truncation)))) .andReturn(control.createMock(InputStream.class)); control.replay(); emailViewPartsFetcherImpl.fetchBodyData(fetchInstruction, 1); control.verify(); }