### Question:
AmqpReadableBuffer implements ReadableBuffer { @Override public ReadableBuffer clear() { buffer.setIndex(0, buffer.capacity()); return this; } AmqpReadableBuffer(ByteBuf buffer); ByteBuf getBuffer(); @Override int capacity(); @Override boolean hasArray(); @Override byte[] array(); @Override int arrayOffset(); @Override ReadableBuffer reclaimRead(); @Override byte get(); @Override byte get(int index); @Override int getInt(); @Override long getLong(); @Override short getShort(); @Override float getFloat(); @Override double getDouble(); @Override ReadableBuffer get(byte[] target, int offset, int length); @Override ReadableBuffer get(byte[] target); @Override ReadableBuffer get(WritableBuffer target); @Override ReadableBuffer slice(); @Override ReadableBuffer flip(); @Override ReadableBuffer limit(int limit); @Override int limit(); @Override ReadableBuffer position(int position); @Override int position(); @Override ReadableBuffer mark(); @Override ReadableBuffer reset(); @Override ReadableBuffer rewind(); @Override ReadableBuffer clear(); @Override int remaining(); @Override boolean hasRemaining(); @Override ReadableBuffer duplicate(); @Override ByteBuffer byteBuffer(); @Override String readUTF8(); @Override String readString(CharsetDecoder decoder);  }### Answer:
@Test public void testClear() { byte[] data = new byte[] { 0, 1, 2, 3, 4}; ByteBuf byteBuffer = Unpooled.wrappedBuffer(data); AmqpReadableBuffer buffer = new AmqpReadableBuffer(byteBuffer); byte[] target = new byte[data.length]; buffer.get(target); assertFalse(buffer.hasRemaining()); assertArrayEquals(data, target); try { buffer.get(target); fail("Should throw an IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ioe) {} buffer.clear(); assertTrue(buffer.hasRemaining()); assertEquals(data.length, buffer.remaining()); buffer.get(target); assertFalse(buffer.hasRemaining()); assertArrayEquals(data, target); }