### Question:
BufferReaderWriterUtil { static boolean writeBuffer(Buffer buffer, ByteBuffer memory) { final int bufferSize = buffer.getSize(); if (memory.remaining() < bufferSize + HEADER_LENGTH) { return false; } memory.putInt(buffer.isBuffer() ? HEADER_VALUE_IS_BUFFER : HEADER_VALUE_IS_EVENT); memory.putInt(bufferSize); memory.put(buffer.getNioBufferReadable()); return true; }    }### Answer:
@Test public void writeByteBufferNotEnoughSpace() { final ByteBuffer memory = ByteBuffer.allocateDirect(10); final Buffer buffer = createTestBuffer(); final boolean written = BufferReaderWriterUtil.writeBuffer(buffer, memory); assertFalse(written); assertEquals(0, memory.position()); assertEquals(memory.capacity(), memory.limit()); }