### Question:
MessageFramer implements Framer { @Override public void close() { if (!isClosed()) { closed = true; if (buffer != null && buffer.readableBytes() == 0) { releaseBuffer(); } commitToSink(true, true); } } MessageFramer(
      Sink sink, WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx); @Override MessageFramer setCompressor(Compressor compressor); @Override MessageFramer setMessageCompression(boolean enable); @Override void setMaxOutboundMessageSize(int maxSize); @Override void writePayload(InputStream message); @Override void flush(); @Override boolean isClosed(); @Override void close(); @Override void dispose();  }### Answer:
@Test public void closeCombinedWithFullSink() { writeKnownLength(framer, new byte[]{3, 14, 1, 5, 9, 2, 6}); verifyNoMoreInteractions(sink); framer.close(); verify(sink).deliverFrame( toWriteBuffer(new byte[] {0, 0, 0, 0, 7, 3, 14, 1, 5, 9, 2, 6}), true, true, 1); verifyNoMoreInteractions(sink); assertEquals(1, allocator.allocCount); checkStats(7, 7); }
@Test public void closeWithoutBufferedFrameGivesNullBuffer() { framer.close(); verify(sink).deliverFrame(null, true, true, 0); verifyNoMoreInteractions(sink); assertEquals(0, allocator.allocCount); checkStats(); }
@Test public void closeIsRentrantSafe() throws Exception { MessageFramer.Sink reentrant = new MessageFramer.Sink() { int count = 0; @Override public void deliverFrame( WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages) { if (count == 0) { framer.close(); count++; } else { fail("received event from reentrant call to close"); } } }; framer = new MessageFramer(reentrant, allocator, statsTraceCtx); writeKnownLength(framer, new byte[]{3, 14}); framer.close(); }