@Test
public void appendHexStringWithByteArrayAndOffsetLength() throws Exception {

    StringBuilder s0 = new StringBuilder(100);
    s0.setLength(0);
    try {
        // a null buffer throws an exception
        HexUtil.appendHexString(null, new byte[0], 0, 0);
        Assert.fail();
    } catch (NullPointerException e) {
        // correct behavior
        //logger.error(e);
    }
    Assert.assertEquals("", s0.toString());
    // a NULL byte array appends nothing (a noop)
    s0.setLength(0);
    HexUtil.appendHexString(s0, null, 0, 0);
    Assert.assertEquals("", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[0], 0, 0);
    Assert.assertEquals("", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[] { 0x34 }, 0, 1);
    Assert.assertEquals("34", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[] { 0x34 }, 1, 0);
    Assert.assertEquals("", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[] { 0x34, 0x35 }, 1, 1);
    Assert.assertEquals("35", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[] { 0x34, 0x35 }, 0, 2);
    Assert.assertEquals("3435", s0.toString());
    s0.setLength(0);
    HexUtil.appendHexString(s0, new byte[] { (byte)0xFF, (byte)0xAB }, 0, 2);
    Assert.assertEquals("FFAB", s0.toString());
    try {
        HexUtil.appendHexString(s0, new byte[0], -1, 0);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        HexUtil.appendHexString(s0, new byte[0], 0, -1);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        // correct behavior
    }
    try {
        HexUtil.appendHexString(s0, new byte[0], 1, 0);
        Assert.fail();
    } catch (ArrayIndexOutOfBoundsException e) {
        // correct behavior
    }
}