EnumSetWritable extends AbstractCollection<E> implements Writable, Configurable { public EnumSet<E> get() { return value; } EnumSetWritable();  EnumSetWritable(EnumSet<E> value, Class<E> elementType);  EnumSetWritable(EnumSet<E> value); @Override Iterator<E> iterator(); @Override int size(); @Override boolean add(E e); void set(EnumSet<E> value, Class<E> elementType); EnumSet<E> get(); @Override @SuppressWarnings("unchecked") void readFields(DataInput in); @Override void write(DataOutput out); @Override boolean equals(Object o); Class<E> getElementType(); @Override int hashCode(); @Override String toString(); @Override Configuration getConf(); @Override void setConf(Configuration conf);  }
@SuppressWarnings("unchecked") @Test public void testSerializeAndDeserializeNonEmpty() throws IOException { DataOutputBuffer out = new DataOutputBuffer(); ObjectWritable.writeObject(out, nonEmptyFlagWritable, nonEmptyFlagWritable .getClass(), null); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); EnumSet<TestEnumSet> read = ((EnumSetWritable<TestEnumSet>) ObjectWritable .readObject(in, null)).get(); assertEquals(read, nonEmptyFlag); }
@SuppressWarnings("unchecked") @Test public void testSerializeAndDeserializeEmpty() throws IOException { boolean gotException = false; try { new EnumSetWritable<TestEnumSet>(emptyFlag); } catch (RuntimeException e) { gotException = true; } assertTrue( "Instantiation of empty EnumSetWritable with no element type class " + "provided should throw exception.", gotException); EnumSetWritable<TestEnumSet> emptyFlagWritable = new EnumSetWritable<TestEnumSet>(emptyFlag, TestEnumSet.class); DataOutputBuffer out = new DataOutputBuffer(); ObjectWritable.writeObject(out, emptyFlagWritable, emptyFlagWritable .getClass(), null); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); EnumSet<TestEnumSet> read = ((EnumSetWritable<TestEnumSet>) ObjectWritable .readObject(in, null)).get(); assertEquals(read, emptyFlag); }
@SuppressWarnings("unchecked") @Test public void testSerializeAndDeserializeNull() throws IOException { boolean gotException = false; try { new EnumSetWritable<TestEnumSet>(null); } catch (RuntimeException e) { gotException = true; } assertTrue( "Instantiation of empty EnumSetWritable with no element type class " + "provided should throw exception", gotException); EnumSetWritable<TestEnumSet> nullFlagWritable = new EnumSetWritable<TestEnumSet>(null, TestEnumSet.class); DataOutputBuffer out = new DataOutputBuffer(); ObjectWritable.writeObject(out, nullFlagWritable, nullFlagWritable .getClass(), null); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); EnumSet<TestEnumSet> read = ((EnumSetWritable<TestEnumSet>) ObjectWritable .readObject(in, null)).get(); assertEquals(read, null); }