builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
// proto field scalar and repeated
builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(1));
builder.addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(1));
TestAllTypes value1 = builder.build();
assertEquals(100, value1.getOptionalSfixed64());
assertEquals(100, value1.getRepeatedInt32(0));
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
value1.getOptionalImportEnum());
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
value1.getRepeatedImportEnum(0));
assertEquals(1, value1.getOptionalForeignMessage().getC());
assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
// Make sure that builder didn't update previously created values
builder.setOptionalSfixed64(200);
builder.setRepeatedInt32(0, 200);
builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_FOO);
builder.setRepeatedImportEnum(0, UnittestImport.ImportEnum.IMPORT_FOO);
builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(2));
builder.setRepeatedForeignMessage(0, ForeignMessage.newBuilder().setC(2));
TestAllTypes value2 = builder.build();
// Make sure value1 didn't change.
assertEquals(100, value1.getOptionalSfixed64());
assertEquals(100, value1.getRepeatedInt32(0));
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
value1.getOptionalImportEnum());
assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
value1.getRepeatedImportEnum(0));
assertEquals(1, value1.getOptionalForeignMessage().getC());
assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
// Make sure value2 is correct
assertEquals(200, value2.getOptionalSfixed64());
assertEquals(200, value2.getRepeatedInt32(0));
assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
value2.getOptionalImportEnum());
assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
value2.getRepeatedImportEnum(0));
assertEquals(2, value2.getOptionalForeignMessage().getC());
assertEquals(2, value2.getRepeatedForeignMessage(0).getC());
}