use of retrofit2.converter.protobuf.PhoneProtos.Phone in project retrofit by square.
the class ProtoConverterFactoryTest method serializeAndDeserialize.
@Test
public void serializeAndDeserialize() throws IOException, InterruptedException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<Phone> call = service.post(Phone.newBuilder().setNumber("(519) 867-5309").build());
Response<Phone> response = call.execute();
Phone body = response.body();
assertThat(body.getNumber()).isEqualTo("(519) 867-5309");
RecordedRequest request = server.takeRequest();
assertThat(request.getBody().readByteString()).isEqualTo(encoded);
assertThat(request.getHeader("Content-Type")).isEqualTo("application/x-protobuf");
}
use of retrofit2.converter.protobuf.PhoneProtos.Phone in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeEmpty.
@Test
public void deserializeEmpty() throws IOException {
server.enqueue(new MockResponse());
Call<Phone> call = service.get();
Response<Phone> response = call.execute();
Phone body = response.body();
assertThat(body.hasNumber()).isFalse();
}
use of retrofit2.converter.protobuf.PhoneProtos.Phone in project retrofit by square.
the class ProtoConverterFactoryTest method deserializeUsesRegistry.
@Test
public void deserializeUsesRegistry() throws IOException {
ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwORAB");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<Phone> call = serviceWithRegistry.get();
Response<Phone> response = call.execute();
Phone body = response.body();
assertThat(body.getNumber()).isEqualTo("(519) 867-5309");
assertThat(body.getExtension(PhoneProtos.voicemail)).isEqualTo(true);
}
Aggregations