### Question:
AvroSerializer implements Serializer<AvroWrapper<T>> { @Override public void serialize(AvroWrapper<T> avroWrapper) throws IOException { mAvroDatumWriter.write(avroWrapper.datum(), mAvroEncoder); mAvroEncoder.flush(); } AvroSerializer(Schema writerSchema);  AvroSerializer(Schema writerSchema, DatumWriter<T> datumWriter); Schema getWriterSchema(); @Override void open(OutputStream outputStream); @Override void serialize(AvroWrapper<T> avroWrapper); @Override void close();  }### Answer:
@Test public void testSerialize() throws IOException { Schema writerSchema = Schema.create(Schema.Type.STRING); AvroSerializer<CharSequence> serializer = new AvroSerializer<>(writerSchema); assertEquals(writerSchema, serializer.getWriterSchema()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); serializer.open(outputStream); serializer.serialize(new AvroKey<>("record1")); serializer.serialize(new AvroKey<>("record2")); serializer.close(); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); Schema readerSchema = Schema.create(Schema.Type.STRING); DatumReader<CharSequence> datumReader = new GenericDatumReader<>(readerSchema); Decoder decoder = DecoderFactory.get().binaryDecoder(inputStream, null); CharSequence record = null; record = datumReader.read(record, decoder); assertEquals("record1", record.toString()); record = datumReader.read(record, decoder); assertEquals("record2", record.toString()); inputStream.close(); }