@Test
public void testGetAllAttachmentsToKeep() throws Exception {

    // Try to delete one approved and one rejected attachment.
    //  -> the approved one should not be deleted.
    Attachment attachmentAccepted = new Attachment().setAttachmentContentId("acceptedAtt").setFilename("att1.file").setCheckStatus(CheckStatus.ACCEPTED);
    Attachment attachmentRejected = new Attachment().setAttachmentContentId("rejectedAtt").setFilename("att2.file").setCheckStatus(CheckStatus.REJECTED);
    Set<Attachment> attachmentsBefore = new HashSet<>();
    attachmentsBefore.add(attachmentAccepted);
    attachmentsBefore.add(attachmentRejected);
    Set<Attachment> attachmentsAfter = new HashSet<>();
    Set<Attachment> attachmentsToKeep = handler.getAllAttachmentsToKeep(attachmentsBefore, attachmentsAfter);
    assertEquals(1, attachmentsToKeep.size());
    assertTrue(attachmentsToKeep.contains(attachmentAccepted));
    assertFalse(attachmentsToKeep.contains(attachmentRejected));
    // Change an attachment
    //  -> it should not be stored twice
    Attachment originalAttachment = new Attachment().setAttachmentContentId("att").setFilename("att.file").setCheckStatus(CheckStatus.ACCEPTED);
    attachmentsBefore = new HashSet<>();
    attachmentsBefore.add(originalAttachment);
    Attachment changedAttachment = originalAttachment.deepCopy().setCheckStatus(CheckStatus.REJECTED);
    attachmentsAfter = new HashSet<>();
    attachmentsAfter.add(changedAttachment);
    attachmentsToKeep = handler.getAllAttachmentsToKeep(attachmentsBefore, attachmentsAfter);
    assertEquals(1, attachmentsToKeep.size());
    assertTrue(attachmentsToKeep.contains(changedAttachment));
}