MavenMetadataParser implements Function<String, Either<Throwable, Response>> { @Override public Either<Throwable, Response> apply(final String newVersion) { if (newVersion == null || newVersion.isEmpty() || newVersion.contains("SNAPSHOT")) { return Either.right(Response.noMoreRecentVersion()); } return getAvailableVersions() .fold(Either::left, r -> processVersion(newVersion, r)); } MavenMetadataParser(final String server);   MavenMetadataParser(final String server, final String groupId, final String artifactId);  MavenMetadataParser(); @Override Either<Throwable, Response> apply(final String newVersion);  }
@Test void checkNullVersion() { final MavenMetadataParser parser = new MavenMetadataParser(serverUrl, "com.github.robozonky", "robozonky"); final Either<Throwable, Response> result = parser.apply(null); assertThat(result.get()).isEqualTo(Response.noMoreRecentVersion()); }
@Test void checkEmptyVersion() { final MavenMetadataParser parser = new MavenMetadataParser(serverUrl, "com.github.robozonky", "robozonky"); final Either<Throwable, Response> result = parser.apply(""); assertThat(result.get()).isEqualTo(Response.noMoreRecentVersion()); }
@Test void checkNonExistentUrl() { server.when(HttpRequest.request()) .respond(HttpResponse.notFoundResponse()); final MavenMetadataParser parser = new MavenMetadataParser(serverUrl, "com.github.robozonky", "robozonky-nonexistent"); final Either<Throwable, Response> result = parser.apply(UUID.randomUUID() .toString()); assertThat(result.getLeft()).isInstanceOf(FileNotFoundException.class); }