### Question:
VersionsHelper { public List<String> getVersionAdvice(Artifact artifact, int maxReleases){ return getVersionAdvice(getVersions(artifact), maxReleases); } VersionsHelper(ArtifactFactory artifactFactory, MavenProject mavenProject, MavenSession mavenSession, ArtifactMetadataSource artifactMetadataSource); String getLatestReleasedVersion(Artifact artifact); String getLatestSnapshotVersion(Artifact artifact); String getLatestSnapshotVersion(List<ArtifactVersion> versions); String getLatestReleasedVersion(List<ArtifactVersion> versions); List<String> getVersionAdvice(Artifact artifact, int maxReleases); List<String> getVersionAdvice(List<ArtifactVersion> allVersions, int maxSize);  }### Answer:
@Test public void getVersionAdvice_shouldContainOnlyLatestSnapshot(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.1.2", "1.5.6", "1.5.7-SNAPSHOT","1.4.5-SNAPSHOT", "1.1.0-SNAPSHOT", "1.3.0-SNAPSHOT"), 6); assertThat(res, contains("1.5.7-SNAPSHOT", "1.5.6", "1.1.2")); }
@Test public void getVersionAdvice_shouldContainNoMoreThanRequestedQuantity(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.4.0", "1.5.0", "1.8.0"), 2); assertThat(res, contains("1.8.0", "1.5.0")); }
@Test public void getVersionAdvice_shouldContainOnlyOneReleaseFromMajorAndMinor(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.5.2", "1.5.6", "1.5.7-SNAPSHOT"), 6); assertThat(res, contains("1.5.7-SNAPSHOT", "1.5.6")); }
@Test public void getVersionAdvice_containSnapshots(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.8.8", "1.8.3", "1.8.10-SNAPSHOT", "1.8.9-alpha"), 3); assertThat(res, hasItem("1.8.10-SNAPSHOT")); }
@Test public void getVersionAdvice_containGivenNumberOfReleases(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.8.8", "1.8.3", "1.8.10-SNAPSHOT", "1.8.9-alpha"), 1); assertThat(res, hasItem("1.8.9-alpha")); assertThat(res, allOf(not(hasItem("1.8.3")), not(hasItem("1.8.9")))); }
@Test public void getVersionAdvice_shouldReturnSortedList(){ List<String> res = helper.getVersionAdvice( createTestVersions("1.1.2", "1.5.6", "1.5.7-SNAPSHOT" , "1.1.2-alpha", "1.1.0-SNAPSHOT", "1.3.0-SNAPSHOT", "1.3.0", "1.1.0"), 6); assertThat(res, contains("1.5.7-SNAPSHOT", "1.5.6", "1.3.0", "1.1.2")); }