### Question:
CyclicIterator implements Iterator<T> { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("iterator", iterator) .append("numberOfTimesToRepeat", numberOfTimesToRepeat == null ? "infinite" : numberOfTimesToRepeat) .append("numberOfRepeatsCompleted", repeats) .append("indexInCurrentRepeat", index) .toString(); } CyclicIterator(Iterator<? extends T> iterator);  CyclicIterator(Iterator<? extends T> iterator, int numberOfTimesToRepeat); @Override boolean hasNext(); @Override T next(); @Override void remove(); @Override String toString();  }### Answer:
@Test public void shouldHaveNumberOfRepeatsAsInfiniteInTheToStringRepresentationIfNoneSupplied() throws Exception { Iterator<String> input = iteratorWith("1", "2", "3"); Iterator<String> iterator = new CyclicIterator<String>(input); String toString = iterator.toString(); assertThat(toString, containsString("numberOfTimesToRepeat=infinite")); }
@Test public void shouldIncludeNumberOfRepeatsInTheToStringRepresentation() throws Exception { Iterator<String> input = iteratorWith("1", "2", "3"); Integer numberOfTimesToRepeat = 5; Iterator<String> iterator = new CyclicIterator<String>(input, numberOfTimesToRepeat); String toString = iterator.toString(); assertThat(toString, containsString("numberOfTimesToRepeat=5")); }
@Test @SuppressWarnings("unchecked") public void shouldIncludeTheIteratorInTheToStringRepresentation() throws Exception { Iterator<String> input = (Iterator<String>) mock(Iterator.class); when(input.toString()).thenReturn("the-iterator"); Iterator<String> iterator = new CyclicIterator<String>(input); String toString = iterator.toString(); assertThat(toString, containsString("the-iterator")); }