Skip to content

Commit

Permalink
Better failure message for characterization test (#954)
Browse files Browse the repository at this point in the history
* Use Truth for better failure message

* Use Truth for better failure message

* remove guard

* manually compute list differences

* rename

* use guarded containsExactly

* use containsExactlyElementsIn

* add extra versions
  • Loading branch information
elharo authored Oct 18, 2019
1 parent 8210229 commit d955279
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -57,24 +58,35 @@ public void testReadBom_coordinates() throws ArtifactDescriptorException {
}

@Test
public void testReadBom_path() throws MavenRepositoryException {
public void testReadBom_path() throws MavenRepositoryException, ArtifactDescriptorException {
Path pomFile = Paths.get("..", "boms", "cloud-oss-bom", "pom.xml");

Bom bom = RepositoryUtility.readBom(pomFile);
Bom currentBom = RepositoryUtility.readBom(pomFile);
Bom oldBom = RepositoryUtility.readBom("com.google.cloud:libraries-bom:2.6.0");
ImmutableList<Artifact> currentArtifacts = currentBom.getManagedDependencies();
ImmutableList<Artifact> oldArtifacts = oldBom.getManagedDependencies();

String coordinates = currentBom.getCoordinates();
Truth.assertThat(coordinates).startsWith("com.google.cloud:libraries-bom:");
Truth.assertThat(coordinates).endsWith("-SNAPSHOT");

ImmutableList<Artifact> artifacts = bom.getManagedDependencies();
Assert.assertEquals(219, artifacts.size());
String coordinates = bom.getCoordinates();
Assert.assertTrue(coordinates.startsWith("com.google.cloud:libraries-bom:"));
Assert.assertTrue(coordinates.endsWith("-SNAPSHOT"));
// This is a characterization test to verify that the managed dependencies haven't changed.
// However sometimes this list does change. If so, we want to
// output the specific difference so we can manually verify whether
// the changes make sense. When they do make sense, we update the test.
if (currentArtifacts.size() != 217) {
Truth.assertThat(currentArtifacts).containsExactlyElementsIn(oldArtifacts);
}
}

@Test
public void testFindVersions() throws MavenRepositoryException {
RepositorySystem system = RepositoryUtility.newRepositorySystem();
ImmutableList<String> versions =
RepositoryUtility.findVersions(system, "com.google.cloud", "libraries-bom");
Truth.assertThat(versions).containsAtLeast("1.1.0", "1.1.1", "1.2.0", "2.0.0").inOrder();
Truth.assertThat(versions)
.containsAtLeast("1.1.0", "1.1.1", "1.2.0", "2.0.0", "2.4.0", "2.5.0", "2.6.0")
.inOrder();
}

@Test
Expand Down

0 comments on commit d955279

Please sign in to comment.