ByteBuffer { public void add(byte b) throws BufferIsFullException { if (isFull()) { throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")"); } this.buffer[this.currentWritePosition] = b; this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length; this.currentBufferSize += 1; } ByteBuffer();  ByteBuffer(int capacity);  ByteBuffer(byte[] bytes);  ByteBuffer(byte[] bytes, int capacity);  ByteBuffer(byte[] bytes, int offset, int length);  ByteBuffer(byte[] bytes, int offset, int length, int capacity);  ByteBuffer(String string0);  ByteBuffer(String string0, int capacity); int size(); int capacity(); int free(); boolean isFree(int count); boolean isEmpty(); boolean isFull(); void clear(); void add(byte b); void add(byte[] bytes); void add(byte[] bytes, int offset, int length); void delete(int count); byte remove(); byte[] remove(int count); int occurrences(byte b); int occurrences(byte[] bytes); ByteBuffer copy(); ByteBuffer copy(int offset, int length); ByteBuffer copy(int offset, int length, int capacity); byte get(int index); byte[] toArray(); byte[] toArray(int offset, int length); byte[] toArray(int offset, int length, int capacity); void toArray(int offset, int length, byte[] targetBuffer, int targetOffset); boolean startsWith(byte[] prefix); boolean endsWith(byte[] prefix); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int offset); @Override int hashCode(); @Override boolean equals(Object obj); boolean equals(byte[] bytes); @Override String toString(); String toHexString(); String toHexString(int offset, int length);  }
@Test(expected=BufferIsFullException.class) public void addToCauseBufferIsFullException() throws BufferException { ByteBuffer buffer = new ByteBuffer(5); for (int i = 0; i < 5; i++) buffer.add((byte)10); buffer.add((byte)11); }
@Test(expected=BufferSizeException.class) public void addWithArrayToCauseBufferSizeException() throws BufferException { ByteBuffer buffer = new ByteBuffer(TEST_BYTES1.length-1); buffer.add(TEST_BYTES1); }
@Test public void addWithArrayEmptyArrayNoException() throws BufferException { byte[] data = new byte[0]; ByteBuffer buffer = new ByteBuffer(1); buffer.add(data); }
@Test(expected=IllegalArgumentException.class) public void addWithArrayNegativeOffset() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(100); buffer.add(TEST_BYTES1, -1, TEST_BYTES1.length); }
@Test(expected=IllegalArgumentException.class) public void addWithArrayNegativeLength() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(100); buffer.add(TEST_BYTES1, 0, -1); }
@Test(expected=IllegalArgumentException.class) public void addWithArrayWithTooLargeLength() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(100); buffer.add(TEST_BYTES1, 0, TEST_BYTES1.length+1); }
@Test(expected=IllegalArgumentException.class) public void addWithArrayWithOffsetAndTooLargeLength() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(6); buffer.add(TEST_BYTES1, 5, TEST_BYTES1.length-4); }
@Test(expected=IllegalArgumentException.class) public void addWithArrayWithLargeOffset() throws BufferException { ByteBuffer buffer = createCircledByteBuffer(TEST_BYTES1.length); buffer.add(TEST_BYTES1, TEST_BYTES1.length, 0); }