Middlewares { public static <T> AsyncHandler<Response<ByteString>> autoSerialize(AsyncHandler<T> inner) { return serialize(new AutoSerializer()).apply(inner); } private  Middlewares(); static AsyncHandler<Response<ByteString>> autoSerialize(AsyncHandler<T> inner); static AsyncHandler<Response<ByteString>> httpPayloadSemantics(
      AsyncHandler<Response<ByteString>> inner); static Middleware<AsyncHandler<?>, AsyncHandler<Response<?>>> replyContentType(
      String contentType); static Middleware<AsyncHandler<?>, AsyncHandler<Response<ByteString>>> serialize(
      Serializer serializer); static Middleware<AsyncHandler<?>, AsyncHandler<Response<ByteString>>> apolloDefaults();  }
@Test public void asShouldSerializeCharSequenceAsString() throws Exception { serializationFuture.complete(new StringBuilder("hi there")); assertThat(getResult(Middlewares.autoSerialize(serializationDelegate)).payload(), equalTo(Optional.of(ByteString.encodeUtf8("hi there")))); }
@Test public void asShouldSerializeStringAsString() throws Exception { serializationFuture.complete("hi there"); assertThat(getResult(Middlewares.autoSerialize(serializationDelegate)).payload(), equalTo(Optional.of(ByteString.encodeUtf8("hi there")))); }
@Test public void asShouldSerializeResponseCharSequenceAsString() throws Exception { serializationFuture.complete(Response.forPayload("hi there")); assertThat(getResult(Middlewares.autoSerialize(serializationDelegate)).payload(), equalTo(Optional.of(ByteString.encodeUtf8("hi there")))); }
@Test public void asShouldNotSerializeByteString() throws Exception { ByteString byteString = ByteString.encodeUtf8("this is binary"); serializationFuture.complete(byteString); assertThat(getResult(Middlewares.autoSerialize(serializationDelegate)).payload(), equalTo(Optional.of(byteString))); }
@Test public void asShouldNotSerializeResponseByteString() throws Exception { ByteString byteString = ByteString.encodeUtf8("this is binary"); serializationFuture.complete(Response.forPayload(byteString)); assertThat(getResult(Middlewares.autoSerialize(serializationDelegate)).payload(), equalTo(Optional.of(byteString))); }
@Test public void asShouldSerializeObjectAsJson() throws Exception { class TestData { public String theString = "hi"; public int theInteger = 42; } serializationFuture.complete(new TestData()); String json = getResult(Middlewares.autoSerialize(serializationDelegate)).payload().get().utf8(); assertThat(json, equalToIgnoringWhiteSpace("{\"theString\":\"hi\",\"theInteger\":42}")); }
@Test public void asShouldSerializeResponseObjectAsJson() throws Exception { class TestData { public String theString = "hi"; public int theInteger = 42; } serializationFuture.complete(Response.forPayload(new TestData())); String json = getResult(Middlewares.autoSerialize(serializationDelegate)).payload().get().utf8(); assertThat(json, equalToIgnoringWhiteSpace("{\"theString\":\"hi\",\"theInteger\":42}")); }