From d33c37de73399d1cff237d987620bc50e20f35f8 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 25 Feb 2023 01:58:15 -0500 Subject: [PATCH 1/3] wip --- .../org/apache/maven/artifact/versioning/ComparableVersion.java | 2 +- .../apache/maven/artifact/versioning/ComparableVersionTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java index ff6310821da9..ef84afdcf5c8 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java @@ -58,7 +58,7 @@ * over {@code 1.0.0.X1}. * * - * @see "Versioning" on Maven Wiki + * @see "Versioning" in the POM reference * @author Kenney Westerhof * @author Hervé Boutemy */ diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 5695a2b9ae1a..6ddc2972287d 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -37,7 +37,6 @@ private Comparable newComparable(String version) { String canonical = ret.getCanonical(); String parsedCanonical = new ComparableVersion(canonical).getCanonical(); - System.out.println("canonical( " + version + " ) = " + canonical); assertEquals( canonical, parsedCanonical, From 7a0fa64e3d76183e232c679ce6715582ca11e189 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 25 Feb 2023 02:37:38 -0500 Subject: [PATCH 2/3] add tests for MNG-7700 --- .../versioning/ComparableVersionTest.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 6ddc2972287d..2f7c579cffeb 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -32,7 +32,7 @@ */ @SuppressWarnings("unchecked") public class ComparableVersionTest { - private Comparable newComparable(String version) { + private ComparableVersion newComparable(String version) { ComparableVersion ret = new ComparableVersion(version); String canonical = ret.getCanonical(); String parsedCanonical = new ComparableVersion(canonical).getCanonical(); @@ -94,11 +94,11 @@ private void checkVersionsOrder(String[] versions) { private void checkVersionsEqual(String v1, String v2) { Comparable c1 = newComparable(v1); Comparable c2 = newComparable(v2); - assertTrue(c1.compareTo(c2) == 0, "expected " + v1 + " == " + v2); - assertTrue(c2.compareTo(c1) == 0, "expected " + v2 + " == " + v1); - assertTrue(c1.hashCode() == c2.hashCode(), "expected same hashcode for " + v1 + " and " + v2); - assertTrue(c1.equals(c2), "expected " + v1 + ".equals( " + v2 + " )"); - assertTrue(c2.equals(c1), "expected " + v2 + ".equals( " + v1 + " )"); + assertEquals(0, c1.compareTo(c2), "expected " + v1 + " == " + v2); + assertEquals(0, c2.compareTo(c1), "expected " + v2 + " == " + v1); + assertEquals(c1.hashCode(), c2.hashCode(), "expected same hashcode for " + v1 + " and " + v2); + assertEquals(c1, c2, "expected " + v1 + ".equals( " + v2 + " )"); + assertEquals(c2, c1, "expected " + v2 + ".equals( " + v1 + " )"); } private void checkVersionsArrayEqual(String[] array) { @@ -207,7 +207,27 @@ public void testVersionComparing() { checkVersionsOrder("2.0.1", "2.0.1-123"); checkVersionsOrder("2.0.1-xyz", "2.0.1-123"); } - + + @Test + public void testLeadingZeroes() { + checkVersionsOrder("0.7", "2"); + checkVersionsOrder( "0.2", "1.0.7"); + } + + @Test + public void testGetCanonical() { + // MNG-7700 + newComparable("0.x"); + newComparable("0-x"); + newComparable("0.rc"); + newComparable("0-1"); + + ComparableVersion version = new ComparableVersion("0.x"); + assertEquals("x", version.getCanonical()); + ComparableVersion version2 = new ComparableVersion("0.2"); + assertEquals("0.2", version2.getCanonical()); + } + /** * Test MNG-5568 edge case * which was showing transitive inconsistency: since A > B and B > C then we should have A > C @@ -342,7 +362,7 @@ public void testReuse() { ComparableVersion c1 = new ComparableVersion("1"); c1.parseVersion("2"); - Comparable c2 = newComparable("2"); + Comparable c2 = newComparable("2"); assertEquals(c1, c2, "reused instance should be equivalent to new instance"); } From 2ec7d3e6d351a9dcfb2a8232f41244f81e5ace88 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 25 Feb 2023 02:40:14 -0500 Subject: [PATCH 3/3] format --- .../versioning/ComparableVersionTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 2f7c579cffeb..fc382046ee0c 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -207,27 +207,27 @@ public void testVersionComparing() { checkVersionsOrder("2.0.1", "2.0.1-123"); checkVersionsOrder("2.0.1-xyz", "2.0.1-123"); } - + @Test public void testLeadingZeroes() { checkVersionsOrder("0.7", "2"); - checkVersionsOrder( "0.2", "1.0.7"); + checkVersionsOrder("0.2", "1.0.7"); } - + @Test public void testGetCanonical() { - // MNG-7700 - newComparable("0.x"); - newComparable("0-x"); - newComparable("0.rc"); - newComparable("0-1"); - - ComparableVersion version = new ComparableVersion("0.x"); - assertEquals("x", version.getCanonical()); - ComparableVersion version2 = new ComparableVersion("0.2"); - assertEquals("0.2", version2.getCanonical()); + // MNG-7700 + newComparable("0.x"); + newComparable("0-x"); + newComparable("0.rc"); + newComparable("0-1"); + + ComparableVersion version = new ComparableVersion("0.x"); + assertEquals("x", version.getCanonical()); + ComparableVersion version2 = new ComparableVersion("0.2"); + assertEquals("0.2", version2.getCanonical()); } - + /** * Test MNG-5568 edge case * which was showing transitive inconsistency: since A > B and B > C then we should have A > C