You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/02/26 18:16:10 UTC

[GitHub] [maven-gpg-plugin] Syquel commented on a change in pull request #12: [MGPG-80] implement GpgVersion equality in adherence to comparibility

Syquel commented on a change in pull request #12:
URL: https://github.com/apache/maven-gpg-plugin/pull/12#discussion_r583828058



##########
File path: src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java
##########
@@ -48,4 +50,22 @@ 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" ) );

Review comment:
       While objects which are equal must produce the same hash code it is neither required nor expected that unequal objects always produce different hash codes.
   `Arrays.hashCode` should already provide a reasonable implementation to minimize hash collisions.
   
   [Object#hashCode JavaDoc](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--):
   > Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.
   > The general contract of hashCode is:
   > [ ... ]
   > * If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
   > * It is not required that if two objects are unequal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org