### Question:
CircularList { public T next() { if(currentIndex == source.size()) currentIndex = 0; T value = source.get(currentIndex); currentIndex++; return value; } CircularList(List<T> source); T next();  }### Answer:
@Test public void when_next_called_with_single_item_in_source_always_returns_same_item() { String item = UUID.randomUUID().toString(); List<String> source = new ArrayList<String>(); source.add(item); CircularList<String> list = new CircularList<String>(source); assertEquals(item, list.next()); assertEquals(item, list.next()); assertEquals(item, list.next()); }
@Test public void when_next_called_with_two_items_in_source_items_are_returned_in_order() { String item1 = UUID.randomUUID().toString(); String item2 = UUID.randomUUID().toString(); List<String> source = new ArrayList<String>(); source.add(item1); source.add(item2); CircularList<String> list = new CircularList<String>(source); assertEquals(item1, list.next()); assertEquals(item2, list.next()); }
@Test public void when_next_called_three_times_with_two_items_in_source_list_is_reset() { String item1 = UUID.randomUUID().toString(); String item2 = UUID.randomUUID().toString(); List<String> source = new ArrayList<String>(); source.add(item1); source.add(item2); CircularList<String> list = new CircularList<String>(source); assertEquals(item1, list.next()); assertEquals(item2, list.next()); assertEquals(item1, list.next()); }