Skip to content

Commit e78eb15

Browse files
committed
core: test: Opaque: Add test for toImmutableOpaque
... demonstrating the difference between mutable and immutable Opaques. Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent bead573 commit e78eb15

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/src/test/java/org/dcache/nfs/util/OpaqueTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotEquals;
5+
import static org.junit.Assert.assertNotSame;
6+
import static org.junit.Assert.assertSame;
57

68
import java.nio.ByteBuffer;
79

@@ -56,4 +58,18 @@ public void testMutableByteArray() throws Exception {
5658
assertNotEquals(bytesOpaque, bufOpaque);
5759
assertNotEquals(bytesOpaque.hashCode(), bufOpaque.hashCode());
5860
}
61+
62+
@Test
63+
public void testToImmutable() throws Exception {
64+
Opaque mutable = Opaque.forMutableByteBuffer(ByteBuffer.wrap(new byte[] {
65+
(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04}), 0, 4);
66+
Opaque mutableToImmutable = mutable.toImmutableOpaque();
67+
assertEquals(mutable, mutableToImmutable);
68+
assertNotSame(mutable, mutableToImmutable);
69+
70+
Opaque immutable = Opaque.forBytes(new byte[] {(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD});
71+
Opaque immutableToImmutable = immutable.toImmutableOpaque();
72+
assertEquals(immutable, immutableToImmutable);
73+
assertSame(immutable, immutableToImmutable);
74+
}
5975
}

0 commit comments

Comments
 (0)