VersionsHandler { public String getLastRelease(final Collection<String> versions) { final List<Version> sorted = versions.stream() .filter(Version::isValid) .map(Version::make) .filter(Optional::isPresent) .map(Optional::get) .filter(Version::isRelease) .sorted((v1, v2) -> { try { return v1.compare(v2); } catch (IncomparableException e) { return 0; } }) .collect(Collectors.toList()); if(sorted.isEmpty()) { if(LOG.isWarnEnabled()) { LOG.warn(String.format("Cannot obtain last release from collection %s", versions.toString())); } return null; } return sorted.get(sorted.size() - 1).toString(); } VersionsHandler(final RepositoryHandler repoHandler); boolean isUpToDate(final DbArtifact artifact); String getLastRelease(final Collection<String> versions); String getLastVersion(final Collection<String> versions);  }
@Test public void getTheLastReleaseOfRegularVersions() throws IncomparableException { final List<String> versions = new ArrayList<String>(); versions.add("0.1.0-1"); versions.add("0.1.0-SNAPSHOT"); versions.add("2.1.0-1"); versions.add("0.1.0-SNAPSHOT"); versions.add("1.1.0-SNAPSHOT"); versions.add("2.0.0-SNAPSHOT"); versions.add("4.0.0-SNAPSHOT"); assertEquals("2.1.0-1", versionsHandler.getLastRelease(versions)); }
@Test public void getTheLastReleaseIfNoRelease() throws IncomparableException { final List<String> versions = new ArrayList<String>(); versions.add("0.1.0-SNAPSHOT"); versions.add("0.1.0-SNAPSHOT"); versions.add("1.1.0-SNAPSHOT"); versions.add("2.0.0-SNAPSHOT"); versions.add("4.0.0-SNAPSHOT"); assertEquals(null, versionsHandler.getLastRelease(versions)); }