CUnion implements PUnion<CUnion,CField> { @Override public String toString() { return descriptor.getQualifiedName() + asString(); } private  CUnion(Builder builder); @Override boolean has(int key); @Override @SuppressWarnings("unchecked") T get(int key); @Nonnull @Override PMessageBuilder<CUnion,CField> mutate(); @Nonnull @Override String asString(); @Override String toString(); @Nonnull @Override CUnionDescriptor descriptor(); @Override boolean unionFieldIsSet(); @Nonnull @Override CField unionField(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(@Nonnull CUnion other);  }
@Test public void testUnionBuilder_merge() { CUnion.Builder a = normal.builder(); CUnion.Builder b = normal.builder(); a.set(1, "first"); b.merge(a.build()); assertThat(b.build().toString(), is("test.TestUnion{first=\"first\"}")); a.set(1, "second"); b.merge(a.build()); assertThat(b.build().toString(), is("test.TestUnion{first=\"second\"}")); a.set(3, struct.builder().set(1, "first").build()); b.set(3, struct.builder().build()); b.merge(a.build()); b.validate(); assertThat(b.build().toString(), is("test.TestUnion{third={first=\"first\"}}")); a.set(3, struct.builder().set(2, "second").build()); b.merge(a.build()); assertThat(b.build().toString(), is("test.TestUnion{third={first=\"first\",second=\"second\"}}")); a.set(5, ImmutableSet.of(1, 2)); b.set(5, ImmutableSet.of()); b.merge(a.build()); assertThat(b.build().toString(), is("test.TestUnion{fifth=[1,2]}")); a.set(6, ImmutableMap.of(1, "first")); b.set(6, ImmutableMap.of()); b.merge(a.build()); assertThat(b.build().toString(), is("test.TestUnion{sixth={1:\"first\"}}")); }