ArtifactAndLicenseComparator implements Comparator<ArtifactAndLicense>, Serializable { @Override public int compare(ArtifactAndLicense o1, ArtifactAndLicense o2) { boolean b1 = o1.getPurl().isPresent(); boolean b2 = o2.getPurl().isPresent(); int compared = 0; if (b1 && b2) { compared = String.CASE_INSENSITIVE_ORDER.compare(o1.getPurl().get(), o2.getPurl().get()); } if (compared == 0) { compared = String.CASE_INSENSITIVE_ORDER.compare(o1.getFilename(), o2.getFilename()); } return compared; }  @Override int compare(ArtifactAndLicense o1, ArtifactAndLicense o2);  }
@Test void same() { TestArtifactAndLicense a1 = new TestArtifactAndLicense("i am a teapot", "com.bosch:foo:23"); int compare = comp.compare(a1, a1); assertThat(compare).isEqualTo(0); }
@Test void compareFilename() { TestArtifactAndLicense a1 = new TestArtifactAndLicense("i am a teapot", "com.bosch:foo:23"); TestArtifactAndLicense a2 = new TestArtifactAndLicense("i am not a teapot", "dom.bosch:foo:23"); int compare = comp.compare(a1, a2); assertThat(compare).isLessThan(0); compare = comp.compare(a2, a1); assertThat(compare).isGreaterThan(0); }
@Test void compareCoordinates() { TestArtifactAndLicense a1 = new TestArtifactAndLicense("i am a teapot", "com.bosch:foo:23"); TestArtifactAndLicense a2 = new TestArtifactAndLicense("i am a teapot", "dom.bosch:foo:23"); int compare = comp.compare(a1, a2); assertThat(compare).isLessThan(0); compare = comp.compare(a2, a1); assertThat(compare).isGreaterThan(0); }