extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
TestMessageSet.Builder builder = TestMessageSet.newBuilder();
TextFormat.merge(messageSetText, extensionRegistry, builder);
TestMessageSet messageSet = builder.build();
assertTrue(messageSet.hasExtension(
TestMessageSetExtension1.messageSetExtension));
assertEquals(123, messageSet.getExtension(
TestMessageSetExtension1.messageSetExtension).getI());
assertTrue(messageSet.hasExtension(
TestMessageSetExtension2.messageSetExtension));
assertEquals("foo", messageSet.getExtension(
TestMessageSetExtension2.messageSetExtension).getStr());
builder = TestMessageSet.newBuilder();
TextFormat.merge(messageSetTextWithRepeatedExtension, extensionRegistry,
builder);
messageSet = builder.build();
assertEquals(456, messageSet.getExtension(
TestMessageSetExtension1.messageSetExtension).getI());
}