assertTrue(newMsg.hasOptionalNestedMessage());
assertEquals(1, newMsg.getOptionalNestedMessage().getBb());
}
public void testMicroOptionalForeignMessage() throws Exception {
TestAllTypesMicro msg = new TestAllTypesMicro();
MicroOuterClass.ForeignMessageMicro foreignMsg =
new MicroOuterClass.ForeignMessageMicro();
assertFalse(foreignMsg.hasC());
foreignMsg.setC(1);
assertTrue(foreignMsg.hasC());
assertFalse(msg.hasOptionalForeignMessage());
msg.setOptionalForeignMessage(foreignMsg);
assertTrue(msg.hasOptionalForeignMessage());
assertEquals(1, msg.getOptionalForeignMessage().getC());
msg.clearOptionalForeignMessage();
assertFalse(msg.hasOptionalForeignMessage());
msg.clearOptionalForeignMessage()
.setOptionalForeignMessage(new MicroOuterClass.ForeignMessageMicro().setC(2));
assertTrue(msg.hasOptionalForeignMessage());
msg.clear();
assertFalse(msg.hasOptionalForeignMessage());
msg.setOptionalForeignMessage(foreignMsg);
byte [] result = msg.toByteArray();
int msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
assertTrue(msgSerializedSize == 5);
assertEquals(result.length, msgSerializedSize);
TestAllTypesMicro newMsg = TestAllTypesMicro.parseFrom(result);
assertTrue(newMsg.hasOptionalForeignMessage());
assertEquals(1, newMsg.getOptionalForeignMessage().getC());
}