### Question:
CryptoUtil { protected static byte[] asBytes(String hexString, byte padByte) throws DecryptException { byte[] number = new byte[hexString.length() / 2]; try { for (int i = 0; i < hexString.length(); i += 2) { int j = Integer.parseInt(hexString.substring(i, i + 2), 16); number[i / 2] = (byte) (j & 0x000000ff); } } catch (StringIndexOutOfBoundsException ex) { ex.printStackTrace(); throw new DecryptException("Invalid hex string"); } return number; } private  CryptoUtil(); static String decrypt(String encrypted); static String encrypt(String decrypted); static int getMaxKeySize(); static final String ENCODING; }### Answer:
@Test public void AsBytes() throws DecryptException { String testHex; byte[] actual; byte[] expected; byte notUsed = -1; testHex = "000000"; expected = new byte[]{0, 0, 0}; actual = CryptoUtil.asBytes(testHex, notUsed); assertByteArrays("3 byte min value", expected, actual); testHex = "ffffff"; expected = new byte[]{-1, -1, -1}; actual = CryptoUtil.asBytes(testHex, notUsed); assertByteArrays("3 byte max value", expected, actual); testHex = "101010"; expected = new byte[]{16, 16, 16}; actual = CryptoUtil.asBytes(testHex, notUsed); assertByteArrays("3 byte 16s place", expected, actual); testHex = "010101"; expected = new byte[]{1, 1, 1}; actual = CryptoUtil.asBytes(testHex, notUsed); assertByteArrays("3 byte 1s place", expected, actual); }
@Test(expected = DecryptException.class) public void AsBytesShouldFailWhenGivenBadInput() throws DecryptException { String testHex; byte notUsed = -1; testHex = "bbb"; CryptoUtil.asBytes(testHex, notUsed); }