diff --git a/rewrite-core/src/main/java/org/openrewrite/semver/LatestRelease.java b/rewrite-core/src/main/java/org/openrewrite/semver/LatestRelease.java index 947cf16e795..18fc5d4b12e 100644 --- a/rewrite-core/src/main/java/org/openrewrite/semver/LatestRelease.java +++ b/rewrite-core/src/main/java/org/openrewrite/semver/LatestRelease.java @@ -100,12 +100,14 @@ static int countVersionParts(String version) { public int compare(@Nullable String currentVersion, String v1, String v2) { if (v1.equalsIgnoreCase(v2)) { return 0; - } - if (v1.equalsIgnoreCase("RELEASE")) { - return v2.equalsIgnoreCase("LATEST") ? -1 : 1; - } - if (v1.equalsIgnoreCase("LATEST")) { + } else if (v1.equalsIgnoreCase("LATEST")) { + return 1; + } else if (v2.equalsIgnoreCase("LATEST")) { + return -1; + } else if (v1.equalsIgnoreCase("RELEASE")) { return 1; + } else if (v2.equalsIgnoreCase("RELEASE")) { + return -1; } String nv1 = normalizeVersion(v1); diff --git a/rewrite-core/src/test/java/org/openrewrite/semver/LatestReleaseTest.java b/rewrite-core/src/test/java/org/openrewrite/semver/LatestReleaseTest.java index b9acf749a8f..fc92187fda7 100644 --- a/rewrite-core/src/test/java/org/openrewrite/semver/LatestReleaseTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/semver/LatestReleaseTest.java @@ -107,10 +107,12 @@ void preReleases() { @Test void releaseOrLatestKeyword_beatsEverything() { assertThat(latestRelease.compare(null, "RELEASE", "1.2.3")).isPositive(); + assertThat(latestRelease.compare(null, "1.2.3", "RELEASE")).isNegative(); assertThat(latestRelease.compare(null, "RELEASE", "999.999.999")).isPositive(); assertThat(latestRelease.compare(null, "RELEASE", "RELEASE")).isZero(); assertThat(latestRelease.compare(null, "LATEST", "1.2.3")).isPositive(); + assertThat(latestRelease.compare(null, "1.2.3", "LATEST")).isNegative(); assertThat(latestRelease.compare(null, "LATEST", "999.999.999")).isPositive(); assertThat(latestRelease.compare(null, "LATEST", "LATEST")).isZero();