### Question:
ArrayListWritableComparable extends ArrayList<E> implements WritableComparable<ArrayListWritableComparable<E>> { public int compareTo(ArrayListWritableComparable<E> obj) { ArrayListWritableComparable<E> that = (ArrayListWritableComparable<E>) obj; for (int i = 0; i < this.size(); i++) { if (i >= that.size()) return 1; Comparable<E> thisField = (Comparable<E>) this.get(i); Comparable<E> thatField = (Comparable<E>) that.get(i); if (thisField.equals(thatField)) { if (i == this.size() - 1) { if (this.size() > that.size()) return 1; if (this.size() < that.size()) return -1; } } else { return thisField.compareTo((E) thatField); } } return 0; } ArrayListWritableComparable();  ArrayListWritableComparable(ArrayList<E> array); void readFields(DataInput in); void write(DataOutput out); int compareTo(ArrayListWritableComparable<E> obj); String toString();  }### Answer:
@Test public void testSorting1() { ArrayListWritableComparable<Text> list1 = new ArrayListWritableComparable<Text>(); ArrayListWritableComparable<Text> list2 = new ArrayListWritableComparable<Text>(); list1.add(new Text("a")); assertTrue(list1.compareTo(list2) > 0); }
@Test public void testSorting2() { ArrayListWritableComparable<Text> list1 = new ArrayListWritableComparable<Text>(); ArrayListWritableComparable<Text> list2 = new ArrayListWritableComparable<Text>(); list1.add(new Text("a")); list2.add(new Text("b")); assertTrue(list1.compareTo(list2) < 0); assertTrue(list2.compareTo(list1) > 0); list2.clear(); list2.add(new Text("a")); assertTrue(list1.compareTo(list2) == 0); list1.add(new Text("a")); list2.add(new Text("b")); assertTrue(list1.compareTo(list2) < 0); assertTrue(list2.compareTo(list1) > 0); list1.add(new Text("a")); assertTrue(list1.compareTo(list2) < 0); }
@Test public void testSorting3() { ArrayListWritableComparable<Text> list1 = new ArrayListWritableComparable<Text>(); ArrayListWritableComparable<Text> list2 = new ArrayListWritableComparable<Text>(); ArrayListWritableComparable<Text> list3 = new ArrayListWritableComparable<Text>(); list1.add(new Text("a")); list2.add(new Text("a")); list2.add(new Text("a")); list3.add(new Text("a")); list3.add(new Text("a")); assertTrue(list2.compareTo(list3) == 0); list3.add(new Text("a")); assertTrue(list1.compareTo(list2) < 0); assertTrue(list1.compareTo(list3) < 0); assertTrue(list2.compareTo(list1) > 0); assertTrue(list2.compareTo(list3) < 0); assertTrue(list3.compareTo(list1) > 0); assertTrue(list3.compareTo(list2) > 0); }