*/
@Test
public void serialize() throws Exception {
WritableUnion union = new WritableUnion(
new IntOption(100),
new LongOption(200L),
new StringOption("Hello, world!"),
new StringOption());
StringBuilder buf = new StringBuilder(100000);
for (int i = 0, n = buf.capacity(); i < n; i++) {
buf.append((char) ('A' + (i * 257 % 26)));
}
((StringOption) union.switchObject(3)).modify(buf.toString());
WritableUnion r0 = new WritableUnion(IntOption.class, LongOption.class, StringOption.class);
union.switchObject(0);
byte[] s0 = ser(union);
des(r0, s0);
assertThat(r0.getPosition(), is(0));
assertThat(r0.getObject(), is((Object) new IntOption(100)));
WritableUnion r1 = new WritableUnion(IntOption.class, LongOption.class, StringOption.class);
union.switchObject(1);
byte[] s1 = ser(union);
des(r1, s1);
assertThat(r1.getPosition(), is(1));
assertThat(r1.getObject(), is((Object) new LongOption(200L)));
WritableUnion r2 = new WritableUnion(IntOption.class, LongOption.class, StringOption.class);
union.switchObject(2);
byte[] s2 = ser(union);
des(r2, s2);