TtorrentDownloader implements Downloader { @Override public synchronized void download( final String torrentFile, final String destinationDirectory) { requireNonNull(torrentFile, "torrentFile must not be null"); requireNonNull(destinationDirectory, "destinationDirectory must not be null"); try { downloadListener.onDownloadStart(torrentFile); int downloadState = tryDownload(torrentFile, destinationDirectory); downloadListener.onDownloadEnd(torrentFile, downloadState); } catch (DownloadException e) { downloadListener.onDownloadEnd(torrentFile, e.getReason()); } } TtorrentDownloader(); synchronized void setTimeout(long millis); @Override synchronized void setDownloadListener(DownloadListener downloadListener); @Override void setEnabled(boolean enabled); @Override synchronized void download(
            final String torrentFile,
            final String destinationDirectory);  }
@Test public void testDownload() throws IOException, NoSuchAlgorithmException { Tracker tracker = startTracker(); Client client = startSeeder(); DownloadListener downloadListener = Mockito.mock(DownloadListener.class); TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); ttorrentDownloader.setDownloadListener(downloadListener); ttorrentDownloader.setTimeout(60 * 1000); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadStart(TORRENT_FILE); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadProgress(TORRENT_FILE, 100); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadEnd(TORRENT_FILE, DownloadState.COMPLETED); File source = new File(CONTENT_DIRECTORY + File.separator + CONTENT_NAME); File result = new File(TEMPORARY_DIRECTORY + File.separator + CONTENT_NAME); assertThat(result.exists()).isTrue(); assertThat(FileUtils.contentEquals(source, result)).isTrue(); client.stop(); tracker.stop(); }