### Question:
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();  }### Answer:
@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); }
@Test public void testMatchCollection() throws Exception { assertThat(new CollectionSizeMatcher<Iterable<?>>(1).matches(Collections.singletonList(new Object())), is(true)); }
@Test public void testNoMatch() throws Exception { when(collection.iterator()).thenReturn(Collections.emptyList().iterator()); assertThat(new CollectionSizeMatcher<Iterable<?>>(1).matches(collection), is(false)); verify(collection).iterator(); verifyNoMoreInteractions(collection); }
@Test public void testNoMatchCollection() throws Exception { assertThat(new CollectionSizeMatcher<Iterable<?>>(0).matches(Collections.singletonList(new Object())), is(false)); }