### Question:
AttachmentConnector extends AttachmentStreamConnector { public void deleteAttachmentDifference(Set<Attachment> attachmentsBefore, Set<Attachment> attachmentsAfter) { deleteAttachmentsByIds(getAttachentContentIdsToBeDeleted(attachmentsBefore,attachmentsAfter)); } AttachmentConnector(DatabaseConnector connector, Duration downloadTimeout);  AttachmentConnector(Supplier<HttpClient> httpClient, String dbName, Duration downloadTimeout); void updateAttachmentContent(AttachmentContent attachment); AttachmentContent getAttachmentContent(String attachmentContentId); void deleteAttachment(String id); void deleteAttachments(Collection<Attachment> attachments); Set<String> getAttachmentContentIds(Collection<Attachment> attachments); void deleteAttachmentDifference(Set<Attachment> attachmentsBefore, Set<Attachment> attachmentsAfter); Set<String> getAttachentContentIdsToBeDeleted(Set<Attachment> attachmentsBefore,
            Set<Attachment> attachmentsAfter); String getSha1FromAttachmentContentId(String attachmentContentId); void setSha1ForAttachments(Set<Attachment> attachments); static boolean isDuplicateAttachment(Set<Attachment> attachments);  }### Answer:
@Test public void testDeleteAttachmentsDifference() throws Exception { Attachment a1 = mock(Attachment.class); when(a1.getAttachmentContentId()).thenReturn("a1cid"); when(a1.getSha1()).thenReturn(null); when(a1.isSetSha1()).thenReturn(false); Attachment a2 = mock(Attachment.class); when(a2.getAttachmentContentId()).thenReturn("a2cid"); when(a2.getSha1()).thenReturn(null); when(a2.isSetSha1()).thenReturn(false); Set<Attachment> before = new HashSet<>(); before.add(a1); before.add(a2); Attachment a3 = mock(Attachment.class); when(a3.getAttachmentContentId()).thenReturn("a1cid"); when(a3.getSha1()).thenReturn("sha1"); when(a3.isSetSha1()).thenReturn(true); Set<Attachment> after = new HashSet<>(); after.add(a3); Set<String> deletedIds = new HashSet<>(); deletedIds.add("a2cid"); attachmentConnector.deleteAttachmentDifference(before, after); verify(connector).deleteIds(deletedIds, AttachmentContent.class); }
@Test public void testDeleteAttachmentsDifferenceOnlyNonAcceptedIsDeleted() throws Exception { Attachment a1 = mock(Attachment.class); when(a1.getAttachmentContentId()).thenReturn("a1"); Attachment a2 = mock(Attachment.class); when(a2.getAttachmentContentId()).thenReturn("a2"); when(a2.getCheckStatus()).thenReturn(CheckStatus.REJECTED); Attachment a3 = mock(Attachment.class); when(a3.getAttachmentContentId()).thenReturn("a3"); when(a3.getCheckStatus()).thenReturn(CheckStatus.ACCEPTED); Set<Attachment> before = new HashSet<>(); before.add(a1); before.add(a2); before.add(a3); Set<Attachment> after = new HashSet<>(); after.add(a1); Set<String> expectedIdsToDelete = new HashSet<>(); expectedIdsToDelete.add("a2"); attachmentConnector.deleteAttachmentDifference(before, after); verify(connector).deleteIds(expectedIdsToDelete, AttachmentContent.class); }