@Test
public void testBytesToHex() {

    byte[] rand = new byte[4];
    new Random().nextBytes(rand);
    String conv = Convert.bytesToHex(rand);
    assertTrue("Bad length of hex string", conv.length() == 8);
    byte[] b = new byte[4];
    try {
        b[0] = (byte)Integer.parseInt(conv.substring(0, 2), 16);
        b[1] = (byte)Integer.parseInt(conv.substring(2, 4), 16);
        b[2] = (byte)Integer.parseInt(conv.substring(4, 6), 16);
        b[3] = (byte)Integer.parseInt(conv.substring(6, 8), 16);
    }
    catch (NumberFormatException e) {
        fail("Conversion of bytes to hex string failed - "+e.getMessage());
    }
    assertArrayEquals("Conversion of bytes to hex string failed",
                      rand, b);
}