ByteArrayUtil { public static String toHex(byte[] byteArray) { if (byteArray == null) { return ""; } StringBuilder hexStringBuilder = new StringBuilder(); for (int i = 0; i < byteArray.length; i++) { hexStringBuilder.append(byteToHex[byteArray[i] & 0xFF]); } return hexStringBuilder.toString(); } 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 public void toHex_null() { String hex = ByteArrayUtil.toHex(null); assertThat(hex.length()).isEqualTo(0); }
@Test public void toHex_empty() { byte[] bytes = new byte[0]; String hex = ByteArrayUtil.toHex(bytes); assertThat(hex.length()).isEqualTo(0); }
@Test public void toHex_bytearray_good() { String hex = ByteArrayUtil.toHex(BYTEARRAY_GOOD); assertThat(hex).isEqualTo(HEXSTRING_GOOD); }