@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")); }
@Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("iterator", iterator) .append("predicate", predicate) .toString(); }
PredicatedIterator extends CachingIterator<T> { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("iterator", iterator) .append("predicate", predicate) .toString(); } }
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); }
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(); }
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();  }