JarDownloader { List<File> download() { List<File> files = new ArrayList<>(); logger.debug("Extract sonar-scanner-api-batch in temp..."); files.add(jarExtractor.extractToTemp("sonar-scanner-api-batch").toFile()); files.addAll(getScannerEngineFiles()); return files; } JarDownloader(ScannerFileDownloader scannerFileDownloader, BootstrapIndexDownloader bootstrapIndexDownloader, FileCache fileCache, JarExtractor jarExtractor, Logger logger);   }
@Test public void should_download_jar_files() throws Exception { File batchJar = temp.newFile("sonar-scanner-api-batch.jar"); when(jarExtractor.extractToTemp("sonar-scanner-api-batch")).thenReturn(batchJar.toPath()); Collection<JarEntry> jars = new ArrayList<>(); jars.add(new JarEntry("cpd.jar", "CA124VADFSDS")); jars.add(new JarEntry("squid.jar", "34535FSFSDF")); when(bootstrapIndexDownloader.getIndex()).thenReturn(jars); JarDownloader jarDownloader = new JarDownloader(scannerFileDownloader, bootstrapIndexDownloader, fileCache, jarExtractor, mock(Logger.class)); List<File> files = jarDownloader.download(); assertThat(files).isNotNull(); verify(bootstrapIndexDownloader).getIndex(); verify(fileCache, times(1)).get(eq("cpd.jar"), eq("CA124VADFSDS"), any(FileCache.Downloader.class)); verify(fileCache, times(1)).get(eq("squid.jar"), eq("34535FSFSDF"), any(FileCache.Downloader.class)); verifyNoMoreInteractions(fileCache); }
@Test public void test_jar_downloader() throws Exception { ServerConnection connection = mock(ServerConnection.class); JarDownloader.ScannerFileDownloader downloader = new JarDownloader.ScannerFileDownloader(connection); File toFile = temp.newFile(); downloader.download("squid.jar", toFile); verify(connection).downloadFile("/batch/file?name=squid.jar", toFile.toPath()); }