ProtobufUtil { static void checkProto2Syntax(Class<? extends Message> clazz, ExtensionRegistry registry) { for (GenericDescriptor d : getRecursiveDescriptorsForClass(clazz, registry)) { Syntax s = d.getFile().getSyntax(); checkArgument( s == Syntax.PROTO2, "Message %s or one of its dependencies does not use proto2 syntax: %s in file %s", clazz.getName(), d.getFullName(), d.getFile().getName()); } } private  ProtobufUtil();   }
@Test public void testVerifyProto2() { checkProto2Syntax(MessageA.class, ExtensionRegistry.getEmptyRegistry()); checkProto2Syntax(MessageB.class, ExtensionRegistry.getEmptyRegistry()); checkProto2Syntax(MessageC.class, ExtensionRegistry.getEmptyRegistry()); checkProto2Syntax(MessageWithMap.class, ExtensionRegistry.getEmptyRegistry()); checkProto2Syntax(ReferencesMessageWithMap.class, ExtensionRegistry.getEmptyRegistry()); }
@Test public void testAnyIsNotProto2() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(Any.class.getCanonicalName()); thrown.expectMessage("in file " + Any.getDescriptor().getFile().getName()); checkProto2Syntax(Any.class, ExtensionRegistry.getEmptyRegistry()); }
@Test public void testDurationIsNotProto2() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(Duration.class.getCanonicalName()); thrown.expectMessage("in file " + Duration.getDescriptor().getFile().getName()); checkProto2Syntax(Duration.class, ExtensionRegistry.getEmptyRegistry()); }