### Question:
ByteArrayBuilder { public ByteArrayBuilder append(final byte[] b, final int off, final int len) { if (b == null) { return this; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } ensureFreeCapacity(len); this.buffer.put(b, off, len); return this; } ByteArrayBuilder();  ByteArrayBuilder(final int initialCapacity); int capacity(); void ensureFreeCapacity(final int freeCapacity); ByteArrayBuilder charset(final Charset charset); ByteArrayBuilder append(final byte[] b, final int off, final int len); ByteArrayBuilder append(final byte[] b); ByteArrayBuilder append(final CharBuffer charBuffer); ByteArrayBuilder append(final char[] b, final int off, final int len); ByteArrayBuilder append(final char[] b); ByteArrayBuilder append(final String s); ByteBuffer toByteBuffer(); byte[] toByteArray(); void reset(); @Override String toString();  }### Answer:
@Test public void testInvalidAppendBytes() throws Exception { final ByteArrayBuilder buffer = new ByteArrayBuilder(); buffer.append((byte[])null, 0, 0); final byte[] tmp = new byte[] { 1, 2, 3, 4}; try { buffer.append(tmp, -1, 0); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, -1); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, 8); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 10, Integer.MAX_VALUE); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 2, 4); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } }
@Test public void testInvalidAppendChars() throws Exception { final ByteArrayBuilder buffer = new ByteArrayBuilder(); buffer.append((char[])null, 0, 0); final char[] tmp = new char[] { 1, 2, 3, 4}; try { buffer.append(tmp, -1, 0); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, -1); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, 8); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 10, Integer.MAX_VALUE); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 2, 4); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } }