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}.</li> * </ul> * - * @see <a href="https://cwiki.apache.org/confluence/display/MAVENOLD/Versioning">"Versioning" on Maven Wiki</a> + * @see <a href="https://maven.apache.org/pom.html#version-order-specification">"Versioning" in the POM reference</a> * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a> */ 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..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 @@ -32,12 +32,11 @@ */ @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(); - System.out.println("canonical( " + version + " ) = " + canonical); assertEquals( canonical, parsedCanonical, @@ -95,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) { @@ -209,6 +208,26 @@ public void testVersionComparing() { 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 <a href="https://issues.apache.org/jira/browse/MNG-5568">MNG-5568</a> edge case * which was showing transitive inconsistency: since A > B and B > C then we should have A > C @@ -343,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"); }