From 41b3e9c25650cf6f8a987efd6c05046c50527f1e Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 18 Oct 2005 18:39:34 +0000 Subject: [PATCH] version comparison fixes git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@326201 13f79535-47bb-0310-9956-ffa450edef68 --- .../versioning/DefaultArtifactVersion.java | 5 ++-- .../DefaultArtifactVersionTest.java | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java index b4162e00e4..a333728dd6 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java @@ -99,17 +99,18 @@ public class DefaultArtifactVersion private int compareIntegers( Integer i1, Integer i2 ) { + // treat null as 0 in comparison if ( i1 == null ? i2 == null : i1.equals( i2 ) ) { return 0; } else if ( i1 == null ) { - return -1; + return -i2.intValue(); } else if ( i2 == null ) { - return 1; + return i1.intValue(); } else { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java index cd5bda690a..809a7e8d8c 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java @@ -126,6 +126,14 @@ public class DefaultArtifactVersionTest assertEquals( "check incremental version", 0, version.getIncrementalVersion() ); assertEquals( "check build number", 0, version.getBuildNumber() ); assertEquals( "check qualifier", "PATCH-1193602", version.getQualifier() ); + + version = new DefaultArtifactVersion( "2.0-1" ); + assertEquals( "check major version", 2, version.getMajorVersion() ); + assertEquals( "check minor version", 0, version.getMinorVersion() ); + assertEquals( "check incremental version", 0, version.getIncrementalVersion() ); + assertEquals( "check build number", 1, version.getBuildNumber() ); + assertEquals( "check qualifier", null, version.getQualifier() ); + assertEquals( "check string value", "2.0-1", version.toString() ); } public void testVersionComparing() @@ -146,10 +154,10 @@ public class DefaultArtifactVersionTest assertTrue( version.compareTo( new DefaultArtifactVersion( "1" ) ) > 0 ); version = new DefaultArtifactVersion( "1.0" ); - assertTrue( version.compareTo( new DefaultArtifactVersion( "1" ) ) > 0 ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1" ) ) == 0 ); version = new DefaultArtifactVersion( "1.0.0" ); - assertTrue( version.compareTo( new DefaultArtifactVersion( "1" ) ) > 0 ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1" ) ) == 0 ); version = new DefaultArtifactVersion( "1.0" ); assertTrue( version.compareTo( new DefaultArtifactVersion( "1.1" ) ) < 0 ); @@ -210,5 +218,17 @@ public class DefaultArtifactVersionTest version = new DefaultArtifactVersion( "1.0-2" ); assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-1" ) ) > 0 ); + + version = new DefaultArtifactVersion( "2.0-0" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "2.0" ) ) == 0 ); + + version = new DefaultArtifactVersion( "2.0-1" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "2.0" ) ) > 0 ); + + version = new DefaultArtifactVersion( "2.0-1" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "2.0.0" ) ) > 0 ); + + version = new DefaultArtifactVersion( "2.0-1" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "2.0.1" ) ) < 0 ); } }