|
23 | 23 |
|
24 | 24 | import org.junit.Test; |
25 | 25 |
|
| 26 | +import java.nio.ByteOrder; |
26 | 27 | import java.util.List; |
27 | 28 |
|
28 | 29 | import static org.junit.Assert.*; |
@@ -235,4 +236,44 @@ public void testToUUIDToShort() { |
235 | 236 | public void testToUUIDEmpty() { |
236 | 237 | Bytes.allocate(0).toUUID(); |
237 | 238 | } |
| 239 | + |
| 240 | + @Test |
| 241 | + public void testToIntArray() { |
| 242 | + assertArrayEquals(new int[]{1}, Bytes.wrap(new byte[]{0, 0, 0, 1}).toIntArray()); |
| 243 | + assertArrayEquals(new int[]{257}, Bytes.wrap(new byte[]{0, 0, 1, 1}).toIntArray()); |
| 244 | + assertArrayEquals(new int[]{65_793}, Bytes.wrap(new byte[]{0, 1, 1, 1}).toIntArray()); |
| 245 | + assertArrayEquals(new int[]{16_843_009}, Bytes.wrap(new byte[]{1, 1, 1, 1}).toIntArray()); |
| 246 | + assertArrayEquals(new int[]{571_211_845}, Bytes.wrap(new byte[]{34, 12, 0, 69}).toIntArray()); |
| 247 | + assertArrayEquals(new int[]{1_290_429_439}, Bytes.wrap(new byte[]{76, (byte) 234, 99, (byte) 255}).toIntArray()); |
| 248 | + |
| 249 | + assertArrayEquals(new int[]{1, 1}, Bytes.wrap(new byte[]{0, 0, 0, 1, 0, 0, 0, 1}).toIntArray()); |
| 250 | + assertArrayEquals(new int[]{257, 1}, Bytes.wrap(new byte[]{0, 0, 1, 1, 0, 0, 0, 1}).toIntArray()); |
| 251 | + assertArrayEquals(new int[]{257, 65_793, 1}, Bytes.wrap(new byte[]{0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1}).toIntArray()); |
| 252 | + } |
| 253 | + |
| 254 | + @Test(expected = IllegalArgumentException.class) |
| 255 | + public void testToIntArrayNotMod4Was5Byte() { |
| 256 | + Bytes.wrap(new byte[]{1, 0, 0, 0, 1}).toIntArray(); |
| 257 | + } |
| 258 | + |
| 259 | + @Test(expected = IllegalArgumentException.class) |
| 260 | + public void testToIntArrayNotMod4Only3Byte() { |
| 261 | + Bytes.wrap(new byte[]{0, 0, 1}).toIntArray(); |
| 262 | + } |
| 263 | + |
| 264 | + @Test |
| 265 | + public void testToIntEmptyArray() { |
| 266 | + assertArrayEquals(new int[0], Bytes.empty().toIntArray()); |
| 267 | + } |
| 268 | + |
| 269 | + @Test |
| 270 | + public void testToIntArrayLittleEndian() { |
| 271 | + assertArrayEquals(new int[]{1}, Bytes.wrap(new byte[]{1, 0, 0, 0}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 272 | + assertArrayEquals(new int[]{257}, Bytes.wrap(new byte[]{1, 1, 0, 0}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 273 | + assertArrayEquals(new int[]{1_290_429_439}, Bytes.wrap(new byte[]{(byte) 255, 99, (byte) 234, 76}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 274 | + |
| 275 | + assertArrayEquals(new int[]{1, 1}, Bytes.wrap(new byte[]{1, 0, 0, 0, 1, 0, 0, 0}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 276 | + assertArrayEquals(new int[]{257, 1}, Bytes.wrap(new byte[]{1, 1, 0, 0, 1, 0, 0, 0}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 277 | + assertArrayEquals(new int[]{257, 65_793, 1}, Bytes.wrap(new byte[]{1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0}, ByteOrder.LITTLE_ENDIAN).toIntArray()); |
| 278 | + } |
238 | 279 | } |
0 commit comments