IsIterableWithSize extends org.hamcrest.collection.IsIterableWithSize<E> { public static <E> Matcher<Iterable<E>> hasSizeFive() { return hasSize(5); } IsIterableWithSize(final int size); static Matcher<Iterable<E>> hasSizeOne(); static Matcher<Iterable<E>> hasSizeTwo(); static Matcher<Iterable<E>> hasSizeThree(); static Matcher<Iterable<E>> hasSizeFour(); static Matcher<Iterable<E>> hasSizeFive(); static Matcher<Iterable<E>> hasSize(final int size);  }
@Test public void testHasSizeFive() throws Exception { final int expectedSize = 5; final Iterable<Object> iterableWithExpectedSize = createIterableWithSize(expectedSize); final Iterable<Object> iterableWithDifferentSize = createIterableWithSize(expectedSize + 1); final Matcher<Iterable<Object>> isIterableWithSizeMatcher = IsIterableWithSize.hasSizeFive(); final boolean matchesOnSameSize = isIterableWithSizeMatcher.matches(iterableWithExpectedSize); final boolean matchesOnDifferentSize = isIterableWithSizeMatcher.matches(iterableWithDifferentSize); BaseMatcherTest.assertMatches(matchesOnSameSize); BaseMatcherTest.assertDoesNotMatch(matchesOnDifferentSize); }