public static void writeAndFlushWithClosePromise(ChannelOutboundInvoker ctx, ByteBuf msg) {
        ctx.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
    }
@Test
    public void testWriteAndFlushWithClosePromise() {
        final ChannelOutboundInvoker ctx = mock(ChannelOutboundInvoker.class);
        final ChannelPromise promise = mock(ChannelPromise.class);

        final byte[] data = "test".getBytes(StandardCharsets.UTF_8);
        final ByteBuf byteBuf = Unpooled.wrappedBuffer(data, 0, data.length);
        when(ctx.writeAndFlush(same(byteBuf))).thenReturn(promise);
        try {
            NettyChannelUtil.writeAndFlushWithClosePromise(ctx, byteBuf);
            verify(ctx).writeAndFlush(same(byteBuf));
            verify(promise).addListener(same(ChannelFutureListener.CLOSE));
        } finally {
            byteBuf.release();
        }
    }