### Question:
EmailViewPartsFetcherImpl implements EmailViewPartsFetcher { @VisibleForTesting void fetchAttachments(Builder emailViewBuilder, MimeMessage mimeMessage, long uid) { MimePart parentMessage = mimeMessage.findRootMimePartInTree(); Collection<MimePart> children = parentMessage.listLeaves(true, true); if (isCalendarOperation(children)) { return; } EmailViewAttachments.Builder attachments = EmailViewAttachments.builder() .uid(uid) .collectionId(collectionId); for (MimePart mp : children) { if (mp.isAttachment() || mp.isNested()) { attachments.addAttachment(mp); } } emailViewBuilder.attachments(attachments.build().getEmailViewAttachments()); } 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 testEmlAttachmentIsALeaf() { String attachmentName = "ForwardedMessage.eml"; long attachmentMailUid = 3; CollectionId attachmentCollection = CollectionId.of(12); int attachmentSize = 1337; MimePart textPlain = MimePartImpl.builder().contentType("text/plain").build(); MimePart rfc822EmbeddedAttachment = MimePartImpl.builder() .contentType("message/rfc822") .contentDisposition("attachment") .size(attachmentSize) .bodyParams(BodyParams.builder().add(new BodyParam("name", attachmentName)).build()) .addChild(MimePartImpl.builder() .contentType("multipart/alternative") .addChild(MimePartImpl.builder().contentType("text/plain").build()) .addChild(MimePartImpl.builder().contentType("text/html").build()) .build()) .build(); MimeMessage message = MimeMessageImpl.builder().addChild( MimePartImpl.builder() .contentType("multipart/mixed") .addChild(textPlain) .addChild(rfc822EmbeddedAttachment) .build()) .build(); String expectedId = "at_" + attachmentMailUid + "_" + "0"; String expectedFileReference = AttachmentHelper .getAttachmentId( attachmentCollection, String.valueOf(attachmentMailUid), rfc822EmbeddedAttachment.getAddress().getAddress(), rfc822EmbeddedAttachment.getFullMimeType(), rfc822EmbeddedAttachment.getContentTransfertEncoding()); EmailViewAttachment expectedAttachment = EmailViewAttachment.builder() .id(expectedId) .displayName(attachmentName) .fileReference(expectedFileReference) .size(attachmentSize) .contentType(ContentType.builder() .contentType("message/rfc822") .add(BodyParams.builder().add(new BodyParam("name", attachmentName)).build()) .build()) .inline(false) .build(); EmailView.Builder emailViewBuilder = control.createMock(EmailView.Builder.class); expect(emailViewBuilder.attachments(Lists.newArrayList(expectedAttachment))).andReturn(emailViewBuilder); EmailViewPartsFetcherImpl emailViewPartsFetcherImpl = new EmailViewPartsFetcherImpl(identityMailTransformerFactory(), null, null, null, null, attachmentCollection); control.replay(); emailViewPartsFetcherImpl.fetchAttachments(emailViewBuilder, message, attachmentMailUid); control.verify(); }