mirror of https://github.com/apache/maven.git
[MNG-7700] test some edge cases with leading zeroes (#1014)
* add tests for MNG-7700
This commit is contained in:
parent
da64ee9c91
commit
b9b6d85957
|
@ -58,7 +58,7 @@ import java.util.Properties;
|
|||
* 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>
|
||||
*/
|
||||
|
|
|
@ -32,12 +32,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
*/
|
||||
@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 @@ public class ComparableVersionTest {
|
|||
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 class ComparableVersionTest {
|
|||
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 class ComparableVersionTest {
|
|||
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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue