### Question:
FilteredIterator extends CachingIterator<T> { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("iterator", iterator) .append("predicate", predicate) .toString(); } FilteredIterator(Iterator<? extends T> iterator, UnaryPredicate<? super T> predicate); @Override String toString();  }### Answer:
@Test @SuppressWarnings("unchecked") public void shouldIncludeIteratorInToStringRepresentation() throws Exception { Iterator<String> input = (Iterator<String>) mock(Iterator.class); Predicate<String> predicate = new Predicate<String>() { public boolean evaluate(String item) { return item.contains("o"); } }; when(input.toString()).thenReturn("the-iterator"); FilteredIterator<String> iterator = new FilteredIterator<String>(input, predicate); String toString = iterator.toString(); assertThat(toString, containsString("the-iterator")); }
@Test public void shouldIncludePredicateInToStringRepresentation() throws Exception { Iterator<String> input = iteratorWith("1", "2", "3"); Predicate<String> predicate = new Predicate<String>() { public boolean evaluate(String item) { return item.contains("o"); } @Override public String toString() { return "the-predicate"; } }; FilteredIterator<String> iterator = new FilteredIterator<String>(input, predicate); String toString = iterator.toString(); assertThat(toString, containsString("the-predicate")); }