DescriptorsTest.java 文件源码

java
阅读 43 收藏 0 点赞 0 评论 0

项目:bazel 作者:
public void testUnknownFieldsDenied() throws Exception {
  FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
      .setName("foo.proto")
      .addMessageType(DescriptorProto.newBuilder()
          .setName("Foo")
          .addField(FieldDescriptorProto.newBuilder()
              .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
              .setTypeName("Bar")
              .setName("bar")
              .setNumber(1)))
      .build();

  try {
    Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
    fail("DescriptorValidationException expected");
  } catch (DescriptorValidationException e) {
    assertTrue(e.getMessage().indexOf("Bar") != -1);
    assertTrue(e.getMessage().indexOf("is not defined") != -1);
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号