### Question:
ComprehensionIterator extends CachingIterator<T> { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("mapper", mapper) .append("iterator", iterator) .append("predicates", predicates) .toString(); } ComprehensionIterator(
            UnaryFunction<? super S, T> mapper,
            Iterator<S> iterator,
            Iterable<? extends UnaryPredicate<? super S>> predicates); @Override String toString();  }### Answer:
@Test public void shouldIncludeTheMappingFunctionInTheToStringRepresentation() throws Exception { UnaryFunction<Integer, Integer> mapper = new UnaryFunction<Integer, Integer>() { @Override public Integer call(Integer integer) { throw new NotImplementedException(); } @Override public String toString() { return "some-mapping-function"; } }; Iterator<Integer> input = listWith(1, 2, 3).iterator(); Predicate<Integer> predicate = Predicates.alwaysTrue(); ComprehensionIterator<Integer, Integer> iterator = new ComprehensionIterator<Integer, Integer>(mapper, input, listWith(predicate)); String toString = iterator.toString(); assertThat(toString, containsString("some-mapping-function")); }
@Test @SuppressWarnings("unchecked") public void shouldIncludeTheIteratorFunctionInTheToStringRepresentation() throws Exception { UnaryFunction<Integer, Integer> mapper = UnaryFunctions.identity(); Iterator<Integer> input = (Iterator<Integer>) mock(Iterator.class); Predicate<Integer> predicate = Predicates.alwaysTrue(); when(input.toString()).thenReturn("the-iterator"); ComprehensionIterator<Integer, Integer> iterator = new ComprehensionIterator<Integer, Integer>(mapper, input, listWith(predicate)); String toString = iterator.toString(); assertThat(toString, containsString("the-iterator")); }
@Test public void shouldIncludeThePredicatesInTheToStringRepresentation() throws Exception { UnaryFunction<Integer, Integer> mapper = UnaryFunctions.identity(); Iterator<Integer> input = iteratorWith(1, 2, 3); Predicate<Integer> predicate = Predicates.alwaysTrue(); List<Predicate<Integer>> predicates = listWith(predicate); ComprehensionIterator<Integer, Integer> iterator = new ComprehensionIterator<Integer, Integer>(mapper, input, predicates); String toString = iterator.toString(); assertThat(toString, containsString(predicates.toString())); }