Skip to content

Commit

Permalink
#235: fix VersionIdentifier to compare java versions correctly (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
salimbouch authored Jun 12, 2024
1 parent 4823886 commit 4fac5c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public VersionComparisonResult compareVersion(VersionSegment other) {
if (!lettersResult.isEqual()) {
return lettersResult;
}
if (!"_".equals(this.separator) && "_".equals(other.separator)) {
return VersionComparisonResult.GREATER;
} else if ("_".equals(this.separator) && !"_".equals(other.separator)) {
return VersionComparisonResult.LESS;
}

if (this.number < other.number) {
return VersionComparisonResult.LESS;
} else if (this.number > other.number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,15 @@ public void testMatchAny() {
assertThat(pattern.matches(VersionIdentifier.of("17.0-SNAPSHOT"))).isTrue();
}

@Test
public void testCompareJavaVersions() {

VersionIdentifier v21_35 = VersionIdentifier.of("21_35");
VersionIdentifier v21_0_2_13 = VersionIdentifier.of("21.0.2_13");
VersionIdentifier v21_0_3_9 = VersionIdentifier.of("21.0.3_9");
assertThat(v21_35).isLessThan(v21_0_2_13);
assertThat(v21_0_2_13).isLessThan(v21_0_3_9);
assertThat(v21_0_3_9).isGreaterThan(v21_35);
}

}

0 comments on commit 4fac5c5

Please sign in to comment.