This is an automated email from the ASF dual-hosted git repository. tabish121 pushed a commit to branch 1.x in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
commit c6a1215e568c88e358c6fd3b826ea5394f27b120 Author: Timothy Bish <[email protected]> AuthorDate: Fri Aug 7 16:05:58 2026 -0400 PROTON-2947 Add tests to cover Binary type hashCode stability (cherry picked from commit 856b7f5627d42d257a1964fe69cd3631557b908d) --- .../org/apache/qpid/protonj2/types/BinaryTest.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/protonj2/src/test/java/org/apache/qpid/protonj2/types/BinaryTest.java b/protonj2/src/test/java/org/apache/qpid/protonj2/types/BinaryTest.java index 03e29c38..69539d20 100644 --- a/protonj2/src/test/java/org/apache/qpid/protonj2/types/BinaryTest.java +++ b/protonj2/src/test/java/org/apache/qpid/protonj2/types/BinaryTest.java @@ -18,6 +18,7 @@ package org.apache.qpid.protonj2.types; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -44,6 +45,10 @@ public class BinaryTest { assertNull(binary.asProtonBuffer()); assertEquals(binary, binary.copy()); assertEquals("", binary.toString()); + + int hash = binary.hashCode(); + + assertEquals(hash, binary.hashCode()); } @Test @@ -92,6 +97,28 @@ public class BinaryTest { assertFalse(bin2.equals(bin1), "Objects should not be equal"); } + @Test + public void testHashCode() { + int length = 10; + + Binary bin1 = createNewRepeatedValueBinary(length, (byte) 1); + Binary bin2 = createNewRepeatedValueBinary(length, (byte) 2); + + int hash1 = bin1.hashCode(); + int hash2 = bin2.hashCode(); + + assertNotEquals(0, hash1); + assertNotEquals(0, hash2); + + assertNotEquals(hash1, hash2); + + assertNotEquals(hash1, bin2.hashCode()); + assertNotEquals(hash2, bin1.hashCode()); + + assertEquals(hash1, bin1.hashCode()); + assertEquals(hash2, bin2.hashCode()); + } + private Binary createSteppedValueBinary(int length) { byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
