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