Skip to content

Commit

Permalink
protobuf: add test for ProtoUtils (grpc#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyane authored and ericgribkoff committed Apr 6, 2018
1 parent 8d3d26d commit d68b2cd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions protobuf/src/test/java/io/grpc/protobuf/ProtoUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.junit.Assert.fail;

import com.google.common.io.ByteStreams;
import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import com.google.protobuf.Type;
import io.grpc.MethodDescriptor.Marshaller;
import io.grpc.Status;
Expand Down Expand Up @@ -60,6 +62,20 @@ public void testJsonRoundtrip() throws Exception {
assertEquals(proto, marshaller.parse(is));
}

@Test
public void testJsonMarshallerFailToPrint() {
Marshaller<Any> marshaller = ProtoUtils.jsonMarshaller(Any.getDefaultInstance());
try {
marshaller.stream(
Any.newBuilder().setValue(ByteString.copyFromUtf8("invalid (no type url)")).build());
fail("Expected exception");
} catch (StatusRuntimeException e) {
assertNotNull(e.getCause());
assertNotNull(e.getMessage());
assertEquals(Status.Code.INTERNAL, e.getStatus().getCode());
}
}

@Test
public void testJsonRepresentation() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
Expand Down

0 comments on commit d68b2cd

Please sign in to comment.