BeaconContentUtil { static byte[] parseBytesOrNull(final String deviceMessageAsHex) { if (deviceMessageAsHex == null) { return null; } final int length = deviceMessageAsHex.length(); final int resultSize = length / 2; if (length % 2 != 0) { throw new IllegalArgumentException("hex string needs to be even-length: " + deviceMessageAsHex); } final byte[] bytes = new byte[resultSize]; for (int pos = 0; pos < resultSize; pos++) { bytes[pos] = (byte) Integer.parseInt(deviceMessageAsHex.substring(pos * 2, pos * 2 + 2), 16); } return bytes; } private  BeaconContentUtil();   }
@Test public void parseBytesOrNullTestForValidValue() throws Exception { byte[] bytes = BeaconContentUtil.parseBytesOrNull("0123"); assertThat(bytes).containsExactly(0x01, 0x23); }
@Test(expected = IllegalArgumentException.class) public void parseBytesOrNullTestForInvalidValue() throws Exception { BeaconContentUtil.parseBytesOrNull("invalid"); fail("Exception is not occurred"); }
@Test public void parseBytesOrNullTestForNull() throws Exception { byte[] bytes = BeaconContentUtil.parseBytesOrNull(null); assertThat(bytes).isNull(); }
@Test public void parseBytesOrNullTestForEmpty() throws Exception { byte[] bytes = BeaconContentUtil.parseBytesOrNull(""); assertThat(bytes).isNotNull().isEmpty(); }