### Question:
ByteBufSerializer extends JsonSerializer<ByteBuf> { @Override public void serialize(ByteBuf byteBuf, JsonGenerator gen, SerializerProvider serializers) throws IOException { byteBuf.resetReaderIndex(); ByteBufInputStream inputStream = new ByteBufInputStream(byteBuf); gen.writeBinary(inputStream, byteBuf.writerIndex()); }  @Override Class<ByteBuf> handledType(); @Override void serializeWithType(ByteBuf byteBuf, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer); @Override void serialize(ByteBuf byteBuf, JsonGenerator gen, SerializerProvider serializers);  }### Answer:
@Test public void serializesGivenByteBuf() throws IOException { ByteBufSerializer serializer = new ByteBufSerializer(); JsonGenerator jsonGenerator = mock(JsonGenerator.class); ByteBuf byteBuf = mock(ByteBuf.class); when(byteBuf.writerIndex()).thenReturn(10); serializer.serialize(byteBuf, jsonGenerator, mock(SerializerProvider.class)); verify(byteBuf).resetReaderIndex(); verify(jsonGenerator).writeBinary(any(), eq(10)); }