@Test public void assertAttachmentsExistShouldThrowWhenAtLeastOneUnknownBlobId() throws MailboxException { BlobId blobId1 = BlobId.of("unknownBlobId1"); BlobId unknownBlobId2 = BlobId.of("unknownBlobId2"); AttachmentId attachmentId1 = AttachmentId.from(blobId1.getRawValue()); AttachmentId unknownAttachmentId2 = AttachmentId.from(unknownBlobId2.getRawValue()); when(attachmentManager.exists(attachmentId1, session)).thenReturn(true); when(attachmentManager.exists(unknownAttachmentId2, session)).thenReturn(false); assertThatThrownBy(() -> sut.assertAttachmentsExist( new ValueWithId.CreationMessageEntry( creationMessageId, creationMessageBuilder.attachments( Attachment.builder().size(12L).type("image/jpeg").blobId(blobId1).build(), Attachment.builder().size(23L).type("image/git").blobId(unknownBlobId2).build()) .build() ), session)) .isInstanceOf(AttachmentsNotFoundException.class) .matches(e -> ((AttachmentsNotFoundException)e).getAttachmentIds() .containsAll(ImmutableSet.of(unknownBlobId2))); }
public void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException { List<Attachment> attachments = entry.getValue().getAttachments(); List<BlobId> notFounds = listAttachmentsNotFound(attachments, session); if (!notFounds.isEmpty()) { throw new AttachmentsNotFoundException(notFounds); } }
AttachmentChecker { public void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException { List<Attachment> attachments = entry.getValue().getAttachments(); List<BlobId> notFounds = listAttachmentsNotFound(attachments, session); if (!notFounds.isEmpty()) { throw new AttachmentsNotFoundException(notFounds); } } }
AttachmentChecker { public void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException { List<Attachment> attachments = entry.getValue().getAttachments(); List<BlobId> notFounds = listAttachmentsNotFound(attachments, session); if (!notFounds.isEmpty()) { throw new AttachmentsNotFoundException(notFounds); } } @Inject  AttachmentChecker(AttachmentManager attachmentManager); }
AttachmentChecker { public void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException { List<Attachment> attachments = entry.getValue().getAttachments(); List<BlobId> notFounds = listAttachmentsNotFound(attachments, session); if (!notFounds.isEmpty()) { throw new AttachmentsNotFoundException(notFounds); } } @Inject  AttachmentChecker(AttachmentManager attachmentManager); void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session); }
AttachmentChecker { public void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException { List<Attachment> attachments = entry.getValue().getAttachments(); List<BlobId> notFounds = listAttachmentsNotFound(attachments, session); if (!notFounds.isEmpty()) { throw new AttachmentsNotFoundException(notFounds); } } @Inject  AttachmentChecker(AttachmentManager attachmentManager); void assertAttachmentsExist(ValueWithId.CreationMessageEntry entry, MailboxSession session);  }