### Question:
HexArray implements Serializable { public static byte[] fromHex(String hex) { byte[] b = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { b[i / 2] = (byte) (hexIndex(hex.charAt(i)) * 16 + hexIndex(hex.charAt(i + 1))); } return b; } HexArray(byte... data); static String toHex(final byte[] data); static String toHex(final byte[] data, final int len); static String toHexShort(final byte[] data, final int maxLen); static byte[] fromHex(String hex); @Override String toString(); byte[] getData(); @Override boolean equals(Object obj); @Override int hashCode();  }### Answer:
@Test public void fromHex() { assertArrayEquals(new byte[]{1}, HexArray.fromHex("01")); assertArrayEquals(new byte[]{((byte) 0xFF)}, HexArray.fromHex("ff")); assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, HexArray.fromHex("0102030405060708090a0b0c")); }
@Test public void malformedHex() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> HexArray.fromHex("0g")); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> HexArray.fromHex("0A")); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> HexArray.fromHex("dupa")); }