@Test
public void toHexStringWithByteArrayAndOffsetLength() throws Exception {

    String s0 = null;
    // a NULL byte array returns an empty string (safe choice)
    s0 = HexUtil.toHexString(null, 0, 0);
    Assert.assertEquals("", s0);
    s0 = HexUtil.toHexString(new byte[0], 0, 0);
    Assert.assertEquals("", s0);
    s0 = HexUtil.toHexString(new byte[] { 0x34 }, 0, 1);
    Assert.assertEquals("34", s0);
    s0 = HexUtil.toHexString(new byte[] { 0x34, 0x35 }, 0, 2);
    Assert.assertEquals("3435", s0);
    s0 = HexUtil.toHexString(new byte[] { (byte)0xFF, (byte)0xAB }, 0, 2);
    Assert.assertEquals("FFAB", s0);
    s0 = HexUtil.toHexString(new byte[] { (byte)0xFF, (byte)0xAB }, 1, 1);
    Assert.assertEquals("AB", s0);
    try {
        HexUtil.toHexString(new byte[0], -1, 0);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        HexUtil.toHexString(new byte[0], 0, -1);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        HexUtil.toHexString(new byte[0], 1, 0);
        Assert.fail();
    } catch (ArrayIndexOutOfBoundsException e) {
        // correct behavior
    }
}