@Test public void testMatch() throws Exception { when(collection.iterator()).thenReturn(Collections.singletonList(new Object()).iterator()); assertThat(new CollectionSizeMatcher<Iterable<?>>(1).matches(collection), is(true)); verify(collection).iterator(); verifyNoMoreInteractions(collection); }
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") public boolean matches(T target) { if (target instanceof Collection) { return ((Collection<?>) target).size() == size; } else { int size = 0; for (Object ignored : target) { size++; } return size == this.size; } }
CollectionSizeMatcher extends ElementMatcher.Junction.AbstractBase<T> { @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") public boolean matches(T target) { if (target instanceof Collection) { return ((Collection<?>) target).size() == size; } else { int size = 0; for (Object ignored : target) { size++; } return size == this.size; } } }
CollectionSizeMatcher extends ElementMatcher.Junction.AbstractBase<T> { @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") public boolean matches(T target) { if (target instanceof Collection) { return ((Collection<?>) target).size() == size; } else { int size = 0; for (Object ignored : target) { size++; } return size == this.size; } } CollectionSizeMatcher(int size); }
CollectionSizeMatcher extends ElementMatcher.Junction.AbstractBase<T> { @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") public boolean matches(T target) { if (target instanceof Collection) { return ((Collection<?>) target).size() == size; } else { int size = 0; for (Object ignored : target) { size++; } return size == this.size; } } CollectionSizeMatcher(int size); @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") boolean matches(T target); @Override String toString(); }
CollectionSizeMatcher extends ElementMatcher.Junction.AbstractBase<T> { @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") public boolean matches(T target) { if (target instanceof Collection) { return ((Collection<?>) target).size() == size; } else { int size = 0; for (Object ignored : target) { size++; } return size == this.size; } } CollectionSizeMatcher(int size); @SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "Iteration required to count size of an iterable") boolean matches(T target); @Override String toString();  }