### Question:
ReusableBuffer { public void shrink(int newSize) { assert (!returned) : "Buffer was already freed and cannot be used anymore" + this.freeStack; if (newSize > size) { throw new IllegalArgumentException("new size must not be larger than old size"); } this.size = newSize; int oldPos = buffer.position(); if (oldPos > newSize) oldPos = 0; ByteBuffer originalBuffer; if (parentBuffer != null) { originalBuffer = parentBuffer; } else { originalBuffer = buffer; } int position = originalBuffer.position(); int limit = originalBuffer.limit(); originalBuffer.position(0); originalBuffer.limit(newSize); this.buffer = originalBuffer.slice(); buffer.position(oldPos); originalBuffer.position(position); originalBuffer.limit(limit); } protected  ReusableBuffer(ByteBuffer buffer, int size);  ReusableBuffer(ByteBuffer nonManaged); static ReusableBuffer wrap(byte[] data); static ReusableBuffer wrap(byte[] data, int offset, int length); ReusableBuffer createViewBuffer(); int capacity(); int capacityUnderlying(); boolean hasArray(); byte[] array(); void flip(); void compact(); void limit(int l); int limit(); void position(int p); int position(); boolean hasRemaining(); ByteBuffer getBuffer(); boolean isReusable(); byte get(); byte get(int index); ReusableBuffer get(byte[] dst); ReusableBuffer get(byte[] dst, int offset, int length); ReusableBuffer put(byte b); ReusableBuffer put(byte[] src); ReusableBuffer put(byte[] src, int offset, int len); ReusableBuffer put(ByteBuffer src); ReusableBuffer put(ReusableBuffer src); int getInt(); ReusableBuffer putInt(int i); long getLong(); ReusableBuffer putLong(long l); double getDouble(); ReusableBuffer putDouble(double d); String getString(); ReusableBuffer putString(String str); ReusableBuffer putShortString(String str); ASCIIString getBufferBackedASCIIString(); ReusableBuffer putBufferBackedASCIIString(ASCIIString str); ReusableBuffer putShort(short s); short getShort(); boolean isDirect(); int remaining(); void clear(); byte[] getData(); void shrink(int newSize); boolean enlarge(int newSize); void range(int offset, int length); ReusableBuffer putBoolean(boolean bool); boolean getBoolean(); int getRefCount(); @Override String toString();  }### Answer:
@Test public final void testShrink() { ReusableBuffer[] buffers = new ReusableBuffer[] { ReusableBuffer.wrap("Yagga Yagga".getBytes()), BufferPool.allocate(12) }; for (ReusableBuffer buf : buffers) { buf.shrink(4); assertEquals(0, buf.position()); assertEquals(4, buf.limit()); assertEquals(4, buf.capacity()); assertEquals(4, buf.remaining()); ReusableBuffer viewBuf = buf.createViewBuffer(); viewBuf.shrink(2); assertEquals(0, viewBuf.position()); assertEquals(2, viewBuf.limit()); assertEquals(2, viewBuf.capacity()); assertEquals(2, viewBuf.remaining()); assertEquals(0, buf.position()); assertEquals(4, buf.limit()); assertEquals(4, buf.capacity()); assertEquals(4, buf.remaining()); if (buf.isReusable()) { BufferPool.free(buf); } } }