Skip to content

Commit 1df62ac

Browse files
committed
Add more readonly and mutable tests
1 parent 1840df7 commit 1df62ac

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,11 @@ public void toLong() throws Exception {
123123
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).toLong(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).toLong());
124124
}
125125

126+
@Test
127+
public void bigInteger() throws Exception {
128+
Bytes b = Bytes.from(example_bytes_four);
129+
assertNotEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).bigInteger(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).bigInteger());
130+
assertEquals(b.byteOrder(ByteOrder.BIG_ENDIAN).bigInteger(), b.byteOrder(ByteOrder.LITTLE_ENDIAN).reverse().bigInteger());
131+
}
126132

127133
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.Test;
2525

2626
import java.nio.ByteOrder;
27+
import java.nio.ReadOnlyBufferException;
2728

2829
import static org.junit.Assert.*;
2930

@@ -178,5 +179,12 @@ public void readOnly() throws Exception {
178179
assertFalse(Bytes.from(example_bytes_twentyfour).isReadOnly());
179180
assertTrue(Bytes.from(example_bytes_twentyfour).readOnly().isReadOnly());
180181
assertTrue(Bytes.from(example_bytes_twentyfour).readOnly().copy().isReadOnly());
182+
183+
assertArrayEquals(example_bytes_twentyfour, Bytes.from(example_bytes_twentyfour).readOnly().internalArray());
184+
try {
185+
Bytes.from(example_bytes_twentyfour).readOnly().array();
186+
fail();
187+
} catch (ReadOnlyBufferException e) {
188+
}
181189
}
182190
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ public void secureWipeShouldThrowException() throws Exception {
100100
Bytes.wrap(new byte[0]).mutable().secureWipe(null);
101101
}
102102

103+
@Test
104+
public void testIfGetSameInstance() throws Exception {
105+
MutableBytes b = fromAndTest(example_bytes_seven).mutable();
106+
assertSame(b, b.mutable());
107+
}
108+
103109
}

0 commit comments

Comments
 (0)