Skip to content

Commit cc11f01

Browse files
committed
Improve tests for hashcode
1 parent 8574b3e commit cc11f01

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/test/java/at/favre/lib/bytes/BytesMiscTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,23 @@ private void testToString(Bytes bytes) {
5252

5353
@Test
5454
public void testHashcode() {
55-
Bytes instance = Bytes.wrap(example_bytes_seven);
55+
Bytes instance = Bytes.from(example_bytes_seven);
5656
assertEquals(instance.hashCode(), instance.hashCode());
5757
assertNotEquals(0, instance.hashCode());
58-
assertEquals(Bytes.wrap(example_bytes_seven).hashCode(), Bytes.from(example_bytes_seven).hashCode());
59-
assertEquals(Bytes.wrap(example2_bytes_seven).hashCode(), Bytes.from(example2_bytes_seven).hashCode());
60-
assertNotEquals(Bytes.wrap(example_bytes_seven).hashCode(), Bytes.wrap(example2_bytes_seven).hashCode());
61-
assertNotEquals(Bytes.wrap(example_bytes_eight).hashCode(), Bytes.wrap(example2_bytes_seven).hashCode());
62-
assertNotEquals(0, Bytes.wrap(example2_bytes_seven).hashCode());
58+
assertEquals(Bytes.from(example_bytes_seven).hashCode(), Bytes.from(example_bytes_seven).hashCode());
59+
assertEquals(Bytes.from(example2_bytes_seven).hashCode(), Bytes.from(example2_bytes_seven).hashCode());
60+
assertNotEquals(Bytes.from(example_bytes_seven).hashCode(), Bytes.from(example2_bytes_seven).hashCode());
61+
assertNotEquals(Bytes.from(example_bytes_eight).hashCode(), Bytes.from(example2_bytes_seven).hashCode());
62+
assertNotEquals(0, Bytes.from(example2_bytes_seven).hashCode());
63+
}
64+
65+
@Test
66+
public void testHashcode_changing() {
67+
MutableBytes instance = Bytes.from(example_bytes_seven).mutable();
68+
assertEquals(instance.hashCode(), Bytes.from(example_bytes_seven).hashCode());
69+
70+
instance.setByteAt(0, (byte) 0x4B);
71+
assertNotEquals(instance.hashCode(), Bytes.from(example_bytes_seven).hashCode());
6372
}
6473

6574
@SuppressWarnings("SimplifiableJUnitAssertion")

0 commit comments

Comments
 (0)