@Test public void deserializeWrongValue() throws Exception { try { converter.fromBody(protoResponse("////"), Phone.class); fail(); } catch (RuntimeException expected) { assertThat(expected.getCause() instanceof InvalidProtocolBufferException); } }
@Test public void deserializeWrongType() throws Exception { try { converter.fromBody(protoResponse(ENCODED_PROTO), ArrayList.class.getGenericSuperclass()); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Expected a raw Class<?> but was java.util.AbstractList<E>"); } }
@Test public void deserializeWrongClass() throws Exception { try { converter.fromBody(protoResponse(ENCODED_PROTO), String.class); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Expected a protobuf message but was java.lang.String"); } }
@Test public void deserialize() throws Exception { Object proto = converter.fromBody(protoResponse(ENCODED_PROTO), Phone.class); assertThat(proto).isEqualTo(PROTO); }
@Test public void serialize() throws Exception { RequestBody body = converter.toBody(PROTO, Phone.class); assertThat(body.contentType().toString()).isEqualTo("application/x-protobuf"); assertBody(body).isEqualTo(ENCODED_PROTO); }