@Test public void requestFileDealsWithExceptionReturningAnEmptyRequest() throws Exception { Path targetDirectory = temporaryFolder.newFolder("target").toPath(); when(httpHelperMock.downloadFile(anyString(), eq(targetDirectory), anyString())).thenThrow(new IOException("Failed to download")); Optional<File> file = hr.requestFile(mavenCoordinate, targetDirectory, classifierInformation); assertThat(file).isEmpty(); }
@Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { String jarBaseName = getExpectedJarBaseName(mavenCoordinate, classifierInformation); File localJarFile = targetDirectory.resolve(jarBaseName).toFile(); if (localJarFile.exists()) { LOGGER.debug("The file " + localJarFile + " already exists and won't be downloaded again"); return Optional.of(localJarFile); } Optional<File> downloadedFile = downloadFileFromUserUrl(mavenCoordinate, targetDirectory, jarBaseName); if (!downloadedFile.isPresent()) { String mavenCentralJarUrl = getJarUrl(mavenCoordinate, jarBaseName, MAVEN_CENTRAL_URL); return tryFileDownload(mavenCentralJarUrl, targetDirectory, jarBaseName); } return downloadedFile; }
HttpRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { String jarBaseName = getExpectedJarBaseName(mavenCoordinate, classifierInformation); File localJarFile = targetDirectory.resolve(jarBaseName).toFile(); if (localJarFile.exists()) { LOGGER.debug("The file " + localJarFile + " already exists and won't be downloaded again"); return Optional.of(localJarFile); } Optional<File> downloadedFile = downloadFileFromUserUrl(mavenCoordinate, targetDirectory, jarBaseName); if (!downloadedFile.isPresent()) { String mavenCentralJarUrl = getJarUrl(mavenCoordinate, jarBaseName, MAVEN_CENTRAL_URL); return tryFileDownload(mavenCentralJarUrl, targetDirectory, jarBaseName); } return downloadedFile; } }
HttpRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { String jarBaseName = getExpectedJarBaseName(mavenCoordinate, classifierInformation); File localJarFile = targetDirectory.resolve(jarBaseName).toFile(); if (localJarFile.exists()) { LOGGER.debug("The file " + localJarFile + " already exists and won't be downloaded again"); return Optional.of(localJarFile); } Optional<File> downloadedFile = downloadFileFromUserUrl(mavenCoordinate, targetDirectory, jarBaseName); if (!downloadedFile.isPresent()) { String mavenCentralJarUrl = getJarUrl(mavenCoordinate, jarBaseName, MAVEN_CENTRAL_URL); return tryFileDownload(mavenCentralJarUrl, targetDirectory, jarBaseName); } return downloadedFile; } HttpRequester(HttpClient httpClient, URL sourceRepositoryUrl);  HttpRequester(HttpClient httpClient); }
HttpRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { String jarBaseName = getExpectedJarBaseName(mavenCoordinate, classifierInformation); File localJarFile = targetDirectory.resolve(jarBaseName).toFile(); if (localJarFile.exists()) { LOGGER.debug("The file " + localJarFile + " already exists and won't be downloaded again"); return Optional.of(localJarFile); } Optional<File> downloadedFile = downloadFileFromUserUrl(mavenCoordinate, targetDirectory, jarBaseName); if (!downloadedFile.isPresent()) { String mavenCentralJarUrl = getJarUrl(mavenCoordinate, jarBaseName, MAVEN_CENTRAL_URL); return tryFileDownload(mavenCentralJarUrl, targetDirectory, jarBaseName); } return downloadedFile; } HttpRequester(HttpClient httpClient, URL sourceRepositoryUrl);  HttpRequester(HttpClient httpClient); @Override Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation); }
HttpRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { String jarBaseName = getExpectedJarBaseName(mavenCoordinate, classifierInformation); File localJarFile = targetDirectory.resolve(jarBaseName).toFile(); if (localJarFile.exists()) { LOGGER.debug("The file " + localJarFile + " already exists and won't be downloaded again"); return Optional.of(localJarFile); } Optional<File> downloadedFile = downloadFileFromUserUrl(mavenCoordinate, targetDirectory, jarBaseName); if (!downloadedFile.isPresent()) { String mavenCentralJarUrl = getJarUrl(mavenCoordinate, jarBaseName, MAVEN_CENTRAL_URL); return tryFileDownload(mavenCentralJarUrl, targetDirectory, jarBaseName); } return downloadedFile; } HttpRequester(HttpClient httpClient, URL sourceRepositoryUrl);  HttpRequester(HttpClient httpClient); @Override Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation);  }