### Question:
ProtoLiteUtils { public static <T extends MessageLite> Marshaller<T> marshaller(T defaultInstance) { return new MessageMarshaller<T>(defaultInstance); } private  ProtoLiteUtils(); @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787") static void setExtensionRegistry(ExtensionRegistryLite newRegistry); static Marshaller<T> marshaller(T defaultInstance); static Metadata.BinaryMarshaller<T> metadataMarshaller(
      T defaultInstance);  }### Answer:
@Test public void testMismatch() throws Exception { Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance()); Enum altProto = Enum.newBuilder().setName(proto.getName()).build(); assertEquals(proto, marshaller.parse(enumMarshaller.stream(altProto))); }
@Test public void introspection() throws Exception { Marshaller<Enum> enumMarshaller = ProtoLiteUtils.marshaller(Enum.getDefaultInstance()); PrototypeMarshaller<Enum> prototypeMarshaller = (PrototypeMarshaller<Enum>) enumMarshaller; assertSame(Enum.getDefaultInstance(), prototypeMarshaller.getMessagePrototype()); assertSame(Enum.class, prototypeMarshaller.getMessageClass()); }
@Test public void testEmpty() throws IOException { Marshaller<Empty> marshaller = ProtoLiteUtils.marshaller(Empty.getDefaultInstance()); InputStream is = marshaller.stream(Empty.getDefaultInstance()); assertEquals(0, is.available()); byte[] b = new byte[10]; assertEquals(-1, is.read(b)); assertArrayEquals(new byte[10], b); assertEquals(-1, is.read(b)); assertArrayEquals(new byte[10], b); assertEquals(-1, is.read()); assertEquals(0, is.available()); }
@Test public void parseFromKnowLengthInputStream() throws Exception { Marshaller<Type> marshaller = ProtoLiteUtils.marshaller(Type.getDefaultInstance()); Type expect = Type.newBuilder().setName("expected name").build(); Type result = marshaller.parse(new CustomKnownLengthInputStream(expect.toByteArray())); assertEquals(expect, result); }