mirror of https://github.com/grpc/grpc-java.git
protobuf: add test for ProtoUtils (#3838)
This commit is contained in:
parent
8d3d26dda1
commit
d68b2cd74a
|
|
@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.protobuf.Any;
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Type;
|
import com.google.protobuf.Type;
|
||||||
import io.grpc.MethodDescriptor.Marshaller;
|
import io.grpc.MethodDescriptor.Marshaller;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
|
|
@ -60,6 +62,20 @@ public class ProtoUtilsTest {
|
||||||
assertEquals(proto, marshaller.parse(is));
|
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
|
@Test
|
||||||
public void testJsonRepresentation() throws Exception {
|
public void testJsonRepresentation() throws Exception {
|
||||||
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
|
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue