### Question:
WritableRawComparableUnion implements Union, WritableRawComparable { @Override public Object switchObject(int newPosition) { this.position = newPosition; return getObject(); } WritableRawComparableUnion(Class<?>... classes);  WritableRawComparableUnion(WritableRawComparable... objects); @Override final int getPosition(); @Override Object switchObject(int newPosition); @Override final Object getObject(); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override int compareTo(WritableRawComparable o); @Override int getSizeInBytes(byte[] buf, int offset); @Override int compareInBytes(byte[] b1, int o1, byte[] b2, int o2); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }### Answer:
@Test public void createFromObject() throws Exception { Union union = new WritableRawComparableUnion( new IntOption(100), new LongOption(200L), new StringOption("Hello, world!")); assertThat(union.switchObject(0), is((Object) new IntOption(100))); assertThat(union.switchObject(1), is((Object) new LongOption(200L))); assertThat(union.switchObject(2), is((Object) new StringOption("Hello, world!"))); }
@Test public void compare() throws Exception { WritableRawComparableUnion a = new WritableRawComparableUnion( new IntOption(100), new LongOption(200L)); WritableRawComparableUnion b = new WritableRawComparableUnion( new IntOption(101), new LongOption(201L)); WritableRawComparableUnion c = new WritableRawComparableUnion( new IntOption(100), new LongOption(200L)); a.switchObject(0); b.switchObject(0); c.switchObject(0); assertThat(cmp(a, b), is(lessThan(0))); assertThat(cmp(b, c), is(greaterThan(0))); assertThat(cmp(c, a), is(equalTo(0))); a.switchObject(1); b.switchObject(1); c.switchObject(1); assertThat(cmp(a, b), is(lessThan(0))); assertThat(cmp(b, c), is(greaterThan(0))); assertThat(cmp(c, a), is(equalTo(0))); a.switchObject(0); c.switchObject(1); assertThat(cmp(a, c), is(not(0))); assertThat(cmp(c, a), is(not(0))); }