@Test
public void testDownloadAttachment() {

    String attachmentId = "attach-0123456789";
    String fileName = "downloadedAttachment.doc";
    Path downloadPath = folder.getRoot().toPath().resolve("downloads");
    String releaseLink = "https://sw360.org/releases/1234567890";
    SW360Release release = new SW360Release();
    release.getLinks().setSelf(new Self(releaseLink));
    SW360SparseAttachment attachment = new SW360SparseAttachment();
    attachment.setFilename(fileName);
    attachment.getLinks().setSelf(new Self("https://sw360.org/attachments/" + attachmentId));
    SW360ReleaseClient releaseClient = mock(SW360ReleaseClient.class);
    when(releaseClient.processAttachment(eq(releaseLink), eq(attachmentId), any()))
            .thenAnswer((Answer<CompletableFuture<Path>>) invocationOnMock -> {
                SW360AttachmentUtils.AttachmentDownloadProcessor processor =
                        invocationOnMock.getArgument(2);
                assertThat(processor.getCopyOptions()).containsOnly(StandardCopyOption.REPLACE_EXISTING);
                try (InputStream stream = Files.newInputStream(testFile())) {
                    return CompletableFuture.completedFuture(processor.processAttachmentStream(stream));
                }
            });
    Optional<Path> optTarget = FutureUtils.block(SW360AttachmentUtils.downloadAttachment(releaseClient,
            release, attachment, downloadPath));
    assertThat(optTarget).isNotEmpty();
    Path target = optTarget.get();
    assertThat(target).isEqualTo(downloadPath.resolve(fileName));
    checkFileDownloaded(target);
}