JarScanner { URL[] download(Collection<String> urls) { ArrayList<URL> downloadedURLs = urls.stream().map(url -> { URI uri = URI.create(url); String downloaderImplClassName = properties.getProperty(String.format("fs.%s.impl", uri.getScheme())); if (null == downloaderImplClassName) { throw new RuntimeException( new UnsupportedSchemeException(uri.getScheme() + " is not supported for downloading jars")); } try { Class clazz = Class.forName(downloaderImplClassName); if (JarDownloader.class.isAssignableFrom(clazz)) { try { return ((JarDownloader) clazz.newInstance()).download(url).toUri().toURL(); } catch (Exception e) { throw new RuntimeException(e); } } else { throw new RuntimeException("Unsupported implementation " + downloaderImplClassName + " of " + JarDownloader.class.getSimpleName()); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }) .collect(Collectors.toCollection(ArrayList::new)); return downloadedURLs.toArray(new URL[downloadedURLs.size()]); } JarScanner(); List<ScanResult> loadJars(final Collection<String> urls, ClassLoader parentLoader);  }
@Test public void testDownload() throws Exception { JarScanner scanner = new JarScanner(); scanner.download(Collections.singletonList(JarScannerTest.class.getResource("/dummy.jar").toString())); }
@Test(expected = RuntimeException.class) public void testDownloadThrowsException() throws Exception { JarScanner scanner = new JarScanner(); scanner.download(Collections.singletonList(JarScannerTest.class.getResource("/dummy1.jar").toString())); }