diff --git a/protobuf/src/test/java/io/grpc/protobuf/ProtoUtilsTest.java b/protobuf/src/test/java/io/grpc/protobuf/ProtoUtilsTest.java index 29f0d1f33d..aa6f529e2a 100644 --- a/protobuf/src/test/java/io/grpc/protobuf/ProtoUtilsTest.java +++ b/protobuf/src/test/java/io/grpc/protobuf/ProtoUtilsTest.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull; 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; @@ -60,6 +62,20 @@ public class ProtoUtilsTest { assertEquals(proto, marshaller.parse(is)); } + @Test + public void testJsonMarshallerFailToPrint() { + Marshaller 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 marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());