version comparison fixes

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@326201 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-18 18:39:34 +00:00
parent d48cbfaef3
commit 41b3e9c256
2 changed files with 25 additions and 4 deletions

View File

@ -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
{

View File

@ -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 );
}
}