### Question:
SparseList extends AbstractList { @Override public Iterator iterator() { if(size == 0) return Collections.EMPTY_LIST.iterator(); return new SparseListNode.SparseListIterator(this, root); }  @Override int size(); @Override void add(int index, Object value); void addNulls(int index, int length); @Override Object get(int index); SparseListNode getNode(int index); @Override Object set(int index, Object value); @Override Object remove(int index); @Override void clear(); @Override Iterator iterator(); void printDebug();  }### Answer:
@Test public void testIterator() { for(int i = 0;i < 995;i++) { boolean addInteger = random.nextBoolean(); int index = sparseTree.isEmpty() ? 0 : random.nextInt(sparseTree.size()); if(addInteger) { sparseTree.add(index, new Integer(i)); } else { sparseTree.add(index, null); } } for(int i = 0;i < 5;i++) { sparseTree.add(sparseTree.size(), null); } Iterator iterator = sparseTree.iterator(); for(int i = 0;i < sparseTree.size();i++) { assertEquals(true, iterator.hasNext()); assertEquals(sparseTree.get(i), iterator.next()); } assertEquals(false, iterator.hasNext()); }