### Question:
IteratorUtils { public static <T> List<T> toList(Iterator<T> it) { List<T> list = new ArrayList<>(); while (it.hasNext()) list.add(it.next()); return list; }  static List<T> toList(Iterator<T> it);  }### Answer:
@Test public void testToList() { List<Integer> source = new ArrayList<>(); for (int i = 0; i < 145; i++) source.add((int) Math.random() * 1000); List<Integer> dest = IteratorUtils.toList(source.iterator()); assertEquals(dest, source); }
@Test public void testEmptyList() { List<Integer> source = new ArrayList<>(); List<Integer> dest = IteratorUtils.toList(source.iterator()); assertTrue(dest.isEmpty()); assertEquals(dest, source); }
@Test public void testNullArg() { try { List<Integer> dest = IteratorUtils.toList(null); fail("Should have failed by now."); } catch (Exception e) { } }