### Question:
RequestSerializer implements Function<Request, byte[]> { @Override public byte[] apply(Request request) { if (!isSet(request)) return new byte[0]; Sc2Api.Request sc2ApiRequest = request.toSc2Api(); sc2ApiRequest = sc2ApiRequest.toBuilder().setId(request.getId()).build(); ByteArrayOutputStream output = new ByteArrayOutputStream(sc2ApiRequest.getSerializedSize()); try { sc2ApiRequest.writeTo(output); } catch (IOException e) { throw new ProtocolException(e); } return output.toByteArray(); }  @Override byte[] apply(Request request);  }### Answer:
@Test void returnsEmptyArrayForNullInput() { assertThat(new RequestSerializer().apply(nothing())).as("serialized request").isEqualTo(EMPTY_ARRAY); }
@Test void serializesSc2ApiRequestToBytes() throws Exception { RequestPing ping = ping(); Sc2Api.Request initialRequest = Sc2Api.Request.newBuilder() .setPing(Sc2Api.RequestPing.newBuilder().build()) .setId(ping.getId()) .build(); byte[] serializedRequest = new RequestSerializer().apply(ping); assertThat(serializedRequest).as("serialized request").isNotEmpty(); assertThat(Sc2Api.Request.parseFrom(serializedRequest)).isEqualTo(initialRequest); }