### Question:
ZeroBuffer { public static ByteBuffer readOnlyBuffer(int length) { ByteBuffer buffer; if (length <= zeroBytes.length) { buffer = ByteBuffer.wrap(zeroBytes, 0, length); } else { buffer = ByteBuffer.allocate(length); put(buffer); buffer.rewind(); } return buffer.asReadOnlyBuffer(); }  static void put(ByteBuffer dst); static void put(ByteBuffer dst, int length); static ByteBuffer readOnlyBuffer(int length);  }### Answer:
@Test public void testReadOnlyBuffer() { ByteBuffer testReadOnlyBuffer; byte[] testBufferArray; testReadOnlyBuffer = ZeroBuffer.readOnlyBuffer(5); Assert.assertTrue( "Test1 - ReadOnlyBuffer should have remaining 5 bytes but it has " + testReadOnlyBuffer.remaining(), testReadOnlyBuffer.remaining() == 5); testBufferArray = new byte[5]; testReadOnlyBuffer.get(testBufferArray); Assert.assertTrue("Test1 - supposed to contain only zero bytes", isFilledWithZeros(testBufferArray, 0, 5)); testReadOnlyBuffer = ZeroBuffer.readOnlyBuffer(64 * 1024); Assert.assertTrue("Test2 - ReadOnlyBuffer should have remaining 64*1024 bytes but it has " + testReadOnlyBuffer.remaining(), testReadOnlyBuffer.remaining() == 64 * 1024); testBufferArray = new byte[64 * 1024]; testReadOnlyBuffer.get(testBufferArray); Assert.assertTrue("Test2 - supposed to contain only zero bytes", isFilledWithZeros(testBufferArray, 0, 64 * 1024)); testReadOnlyBuffer = ZeroBuffer.readOnlyBuffer(128 * 1024); Assert.assertTrue("Test3 - ReadOnlyBuffer should have remaining 128*1024 bytes but it has " + testReadOnlyBuffer.remaining(), testReadOnlyBuffer.remaining() == 128 * 1024); testBufferArray = new byte[128 * 1024]; testReadOnlyBuffer.get(testBufferArray); Assert.assertTrue("Test3 - supposed to contain only zero bytes", isFilledWithZeros(testBufferArray, 0, 128 * 1024)); }