### Question:
MongoWireReplyEncoder extends MessageToByteEncoder<MongoReply> { @Override protected void encode(ChannelHandlerContext ctx, MongoReply reply, ByteBuf buf) { buf.writeIntLE(0); buf.writeIntLE(reply.getHeader().getRequestID()); buf.writeIntLE(reply.getHeader().getResponseTo()); buf.writeIntLE(OpCode.OP_REPLY.getId()); buf.writeIntLE(reply.getFlags()); buf.writeLongLE(reply.getCursorId()); buf.writeIntLE(reply.getStartingFrom()); final List<Document> documents = reply.getDocuments(); buf.writeIntLE(documents.size()); for (Document document : documents) { try { BsonEncoder.encodeDocument(document, buf); } catch (RuntimeException e) { log.error("Failed to encode {}", document, e); ctx.channel().close(); throw e; } } log.debug("wrote reply: {}", reply); final int writerIndex = buf.writerIndex(); buf.setIntLE(0, writerIndex); }    }### Answer:
@Test void testExceptionHandling() throws Exception { MongoWireReplyEncoder mongoWireEncoder = new MongoWireReplyEncoder(); MessageHeader header = new MessageHeader(0, 0); MongoReply reply = new MongoReply(header, new Document("key", Missing.getInstance())); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> mongoWireEncoder.encode(ctx, reply, Unpooled.buffer())) .withMessageContaining("Unexpected missing value. This must not happen. Please report a bug."); verify(channel).close(); }