DownloadManager { public int add(DownloadRequest request) { request = checkNotNull(request, "request == null"); if (isDownloading(request.uri().toString())) { return -1; } request.context(context); request.downloader(downloader.copy()); return downloadRequestQueue.add(request) ? request.downloadId() : -1; } DownloadManager(Builder builder); int add(DownloadRequest request); DownloadState query(int downloadId); boolean isDownloading(int downloadId); boolean isDownloading(String url); int getTaskSize(); boolean cancel(int downloadId); void cancelAll(); void release(); Builder newBuilder();  }
@Test public void testDownload() throws Exception { int downloadId = downloadManager.add(request); assertEquals(1, downloadId); }
@Test public void testDuplicate() throws Exception { int downloadId = downloadManager.add(request); assertEquals(1, downloadId); int downloadId2 = downloadManager.add(request); assertEquals(-1, downloadId2); }