List<IntWritable> list = new ArrayList<IntWritable>();
list.add(new IntWritable(1));
list.add(new IntWritable(2));
list.add(new IntWritable(3));
CollectionWritable c = new CollectionWritable(IntWritable.class, list);
DataOutputBuffer buf = new DataOutputBuffer();
c.write(buf);
DataInputBuffer in = new DataInputBuffer();
in.reset(buf.getData(), buf.getLength());
CollectionWritable roundTripped = new CollectionWritable();
roundTripped.readFields(in);
Assert.assertEquals(list, roundTripped.getCollection());
Iterator<? extends Writable> it = roundTripped.getCollection().iterator();
Assert.assertEquals(new IntWritable(1), it.next());
Assert.assertEquals(new IntWritable(2), it.next());
Assert.assertEquals(new IntWritable(3), it.next());
Assert.assertTrue(!it.hasNext());
}