protobuf: add test for ProtoUtils (#3838)

This commit is contained in:
Shohei Kamimori 2018-04-07 02:10:08 +09:00 committed by Eric Gribkoff
parent 8d3d26dda1
commit d68b2cd74a
1 changed files with 16 additions and 0 deletions

View File

@ -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<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());