ByteArrayUtil { public static int threeBytesToInt(byte[] bytes, int offset) { if (bytes == null || bytes.length < offset + 3 || offset < 0) { throw new IllegalArgumentException("Bad data for converting 3-byte integers."); } return (bytes[offset] & 0xFF) << 16 | (bytes[offset + 1] & 0xFF) << 8 | (bytes[offset + 2] & 0xFF); } private  ByteArrayUtil(); static byte[] fromHex(String hex); static String toHex(byte[] byteArray); static int twoBytesToInt(byte[] bytes, int offset); static int twoBytesSignedToInt(byte[] bytes, int offset); static int threeBytesToInt(byte[] bytes, int offset); static int threeBytesSignedToInt(byte[] bytes, int offset); static int fourBytesToInt(byte[] bytes, int offset);  }
@Test(expected = IllegalArgumentException.class) public void threeBytesToInt_null() { int value = ByteArrayUtil.threeBytesToInt(null, 0); }
@Test(expected = IllegalArgumentException.class) public void threeBytesToInt_negative_offset() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_GOOD, -1); }
@Test(expected = IllegalArgumentException.class) public void threeBytesToInt_too_short_buffer_1() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_LEN_2, 0); }
@Test(expected = IllegalArgumentException.class) public void threeBytesToInt_too_short_buffer_2() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_LEN_3, 1); }
@Test public void threeBytesToInt_buffer_ok_1() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_LEN_3, 0); assertThat(value).isEqualTo(0x123456); }
@Test public void threeBytesToInt_buffer_ok_2() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_GOOD, 0); assertThat(value).isEqualTo(0x123456); }
@Test public void threeBytesToInt_buffer_ok_3() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_GOOD, 1); assertThat(value).isEqualTo(0x345678); }
@Test public void threeBytesToInt_buffer_ok_4() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_GOOD, 4); assertThat(value).isEqualTo(0x90ABCD); }
@Test public void threeBytesToInt_buffer_ok_5() { int value = ByteArrayUtil.threeBytesToInt(BYTEARRAY_GOOD, 13); assertThat(value).isEqualTo(0x654321); }