Skip to content

Commit

Permalink
Merge pull request #12 from Syquel/bugfix/MGPG-80_equality
Browse files Browse the repository at this point in the history
[MGPG-80] implement GpgVersion equality in adherence to comparibility
  • Loading branch information
elharo authored Mar 1, 2021
2 parents b38c638 + 7438b37 commit 4016721
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -123,4 +124,28 @@ public String toString()
return versionStringBuilder.toString();
}

@Override
public boolean equals( final Object other )
{
if ( this == other )
{
return true;
}

if ( !( other instanceof GpgVersion ) )
{
return false;
}

final GpgVersion that = (GpgVersion) other;

return compareTo( that ) == 0;
}

@Override
public int hashCode()
{
return Arrays.hashCode( versionSegments );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void test()
GpgVersionConsumer consumer = new GpgVersionConsumer();
consumer.consumeLine( "gpg (GnuPG/MacGPG2) 2.2.10" );

assertThat( consumer.getGpgVersion().toString(), is( GpgVersion.parse( "2.2.10" ).toString() ) );
assertThat( consumer.getGpgVersion(), is( GpgVersion.parse( "2.2.10" ) ) );
}

}
23 changes: 23 additions & 0 deletions src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

/**
Expand All @@ -48,4 +50,25 @@ public void testOpposite()
assertFalse( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
.isBefore( GpgVersion.parse( "2.0.26" ) ) );
}

@Test
public void testEquality()
{
assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) );
assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.1" ) );
assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ), GpgVersion.parse( "2.2.10" ) );
assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ), GpgVersion.parse( "2.0.26" ) );

assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode() );
assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.1" ).hashCode() );
assertEquals( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).hashCode(), GpgVersion.parse( "2.2.10" ).hashCode() );
assertEquals( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" ).hashCode(), GpgVersion.parse( "2.0.26" ).hashCode() );

assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2.0" ) );
assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ), GpgVersion.parse( "2.2" ) );

assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2.0" ).hashCode() );
assertNotEquals( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).hashCode(), GpgVersion.parse( "2.2" ).hashCode() );
}

}

0 comments on commit 4016721

Please sign in to comment.