### Question:
ChannelStatisticsHandler extends ChannelDuplexHandler { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof ByteBuf) { sentBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { sentBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } super.write(ctx, msg, promise); } ChannelStatisticsHandler(MetricRegistry metricRegistry); @Override void channelRegistered(ChannelHandlerContext ctx); @Override void channelUnregistered(ChannelHandlerContext ctx); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);  }### Answer:
@Test public void countsSentBytes() throws Exception { ByteBuf buf = httpResponseAsBuf(OK, "Response from server"); this.handler.write(mock(ChannelHandlerContext.class), buf, mock(ChannelPromise.class)); assertThat(countOf("connections.bytes-sent"), is((long) buf.readableBytes())); }