Downloader { public File get(String url, String localDestination, Consumer<ProgressEntity> onChange) { try { return get(new URL(url), new File(localDestination), onChange); } catch (MalformedURLException e) { throw new DownloadException(String.format(EXCEPTION_ITEM_DOWNLOAD_FAILED, url), e); } } Downloader(FileSizeUtilities fileSizeUtilities); File get(String url, String localDestination, Consumer<ProgressEntity> onChange); File get(String url, String localDestination, Map<String, String> headers,
            Consumer<ProgressEntity> onChange); File get(URL url, File localDestination, Map<String, String> headers, Consumer<ProgressEntity> onChange); File get(URL url, File localDestination, Consumer<ProgressEntity> onChange); String get(String url, Consumer<ProgressEntity> onChange); String get(String url, Map<String, String> headers, Consumer<ProgressEntity> onChange); String get(URL url, Consumer<ProgressEntity> onChange); byte[] getBytes(URL url, Consumer<ProgressEntity> onChange); boolean isUpdateAvailable(String localFile, String url); boolean isUpdateAvailable(File localFile, URL url);  }
@Test public void testGetDownloadFileFileIsDownloaded() throws Exception { mockServer.when(request().withMethod("GET").withPath("/test.txt")).respond(response().withStatusCode(200) .withHeaders(new Header("Content-Type", "application/config")).withBody("Content file to download")); File temporaryFile = File.createTempFile("test", "txt"); temporaryFile.deleteOnExit(); new Downloader(new FileSizeUtilities()).get(mockServerURL, temporaryFile, e -> { }); String fileContent = IOUtils.toString(new FileReader(temporaryFile)); assertEquals("Content file to download", fileContent); }
@Test public void testGetDownloadFileInAStringFileIsDownloaded() throws Exception { mockServer.when(request().withMethod("GET").withPath("/test2.txt")).respond(response().withStatusCode(200) .withHeaders(new Header("Content-Type", "application/config")).withBody("Content file to download 2")); String result = new Downloader(new FileSizeUtilities()).get(mockServerURLFile2, e -> { }); assertEquals("Content file to download 2", result); }