Skip to content

Commit

Permalink
Fix comparison of repo URI
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Nov 7, 2023
1 parent 2ff68db commit 73a9586
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,46 @@ private void compareMarker(SoftAssertions softAssertions, Marker comparingMarker
private void compareMavenResolutionResultMarker(SoftAssertions softAssertions, MavenResolutionResult comparing, MavenResolutionResult tested) {
softAssertions.assertThat(tested)
.usingRecursiveComparison()
.withEqualsForFieldsMatchingRegexes(
(Object fi1, Object fi2) -> {
if(fi1 == null) {
if(fi2 == null) {
return true;
}
return false;
}
boolean equals = fi1.equals(fi2);
if(equals) {
return true;
}
if(fi1.getClass() == fi1.getClass()) {
if(fi1 instanceof URI) {
URI f1 = (URI) fi1;
URI f2 = (URI) fi2;
return equals ? true : f1.getScheme().equals(f2.getScheme()) &&
f1.getHost().equals(f2.getHost()) &&
f1.getPath().equals(f2.getPath()) &&
f1.getFragment().equals(f2.getFragment());
} else if(fi1 instanceof String) {
try {
URI f1 = new URI((String) fi1);
URI f2 = new URI((String) fi2);
return equals ? true : f1.getScheme().equals(f2.getScheme()) &&
f1.getHost() == null ? (f2.getHost() == null ? true : false) : f1.getHost().equals(f2.getHost()) &&
f1.getPath().equals(f2.getPath()) &&
f1.getFragment().equals(f2.getFragment());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
} else {
return false;
}
} else {
return false;
}

},
".*\\.repository")
.ignoringFields(
"modules",
"dependencies",
Expand Down Expand Up @@ -276,6 +316,9 @@ private void compareMavenResolutionResultMarker(SoftAssertions softAssertions, M
.usingRecursiveComparison()
.withEqualsForFieldsMatchingRegexes(
(Object fi1, Object fi2) -> {
if(fi1 == null) {
return false;
}
boolean equals = fi1.equals(fi2);
if(equals) {
return true;
Expand Down

0 comments on commit 73a9586

Please sign in to comment.