LazyMessageLiteTest.java 文件源码

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

项目:protobuf-java-shaded-261 作者:
public void testLaziness() throws InvalidProtocolBufferException {
  LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
      .setNum(2)
      .build();
  LazyMessageLite outer = LazyMessageLite.newBuilder()
      .setNum(1)
      .setInner(inner)
      .setOneofInner(inner)
      .build();
  ByteString bytes = outer.toByteString();


  // The parser for inner / oneofInner message shouldn't be used if
  // getInner / getOneofInner is not called.
  LazyInnerMessageLite.PARSER = EasyMock.createStrictMock(Parser.class);

  EasyMock.replay(LazyInnerMessageLite.PARSER);

  LazyMessageLite deserialized = LazyMessageLite.parseFrom(bytes);
  assertEquals(1, deserialized.getNum());
  assertEquals(421,  deserialized.getNumWithDefault());

  EasyMock.verify(LazyInnerMessageLite.PARSER);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号