MetadataConverter { public static Metadata toMetadata(Error error) { checkNotNull(error); Metadata metadata = new Metadata(); metadata.put(KEY, error.toByteArray()); return metadata; } private  MetadataConverter(); static Metadata toMetadata(Error error); static Optional<Error> toError(Metadata metadata);  }
@SuppressWarnings("ConstantConditions") @Test @DisplayName("convert Error to Metadata") void convertError() throws InvalidProtocolBufferException { Error error = Error.getDefaultInstance(); Metadata metadata = MetadataConverter.toMetadata(error); byte[] bytes = metadata.get(MetadataConverter.KEY); assertEquals(error, Error.parseFrom(bytes)); }