[MNG-4227] DefaultArtifactVersion equals implementation does not handle null

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@790712 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-07-02 19:08:35 +00:00
parent 8380f2d92e
commit 553fce0f1a
2 changed files with 21 additions and 0 deletions

View File

@ -56,6 +56,16 @@ public class DefaultArtifactVersion
@Override
public boolean equals( Object other )
{
if ( this == other )
{
return true;
}
if ( !( other instanceof ArtifactVersion ) )
{
return false;
}
return compareTo( other ) == 0;
}

View File

@ -177,6 +177,16 @@ public class DefaultArtifactVersionTest
assertEquals( v1.hashCode(), v2.hashCode() );
}
public void testEqualsNullSafe()
{
assertFalse( newArtifactVersion( "1" ).equals( null ) );
}
public void testEqualsTypeSafe()
{
assertFalse( newArtifactVersion( "1" ).equals( "non-an-artifact-version-instance" ) );
}
private void assertVersionOlder( String left, String right )
{
assertTrue( left + " should be older than " + right,
@ -192,4 +202,5 @@ public class DefaultArtifactVersionTest
assertTrue( right + " should be equal to " + left,
newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0 );
}
}