示例#1
0
 @Test
 public void deserializeWrongValue() throws Exception {
   try {
     converter.fromBody(protoResponse("////"), Phone.class);
     fail();
   } catch (RuntimeException expected) {
     assertThat(expected.getCause() instanceof InvalidProtocolBufferException);
   }
 }
示例#2
0
 @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>");
   }
 }
示例#3
0
 @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");
   }
 }
示例#4
0
 @Test
 public void deserialize() throws Exception {
   Object proto = converter.fromBody(protoResponse(ENCODED_PROTO), Phone.class);
   assertThat(proto).isEqualTo(PROTO);
 }
示例#5
0
 @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);
 }