1 package org.hamcrest.collection; 2 3 import org.hamcrest.AbstractMatcherTest; 4 import org.hamcrest.Matcher; 5 6 import java.util.ArrayList; 7 import java.util.Collection; 8 9 import static java.util.Arrays.asList; 10 import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; 11 12 public class IsEmptyIterableTest extends AbstractMatcherTest { 13 14 @Override createMatcher()15 protected Matcher<Iterable<?>> createMatcher() { 16 return emptyIterable(); 17 } 18 testMatchesAnEmptyIterable()19 public void testMatchesAnEmptyIterable() { 20 assertMatches("empty iterable", createMatcher(), emptyCollection()); 21 } 22 testDoesNotMatchAnIterableWithItems()23 public void testDoesNotMatchAnIterableWithItems() { 24 assertDoesNotMatch("iterable with an item", createMatcher(), collectionOfValues()); 25 } 26 testHasAReadableDescription()27 public void testHasAReadableDescription() { 28 assertDescription("an empty iterable", createMatcher()); 29 } 30 testCompiles()31 public void testCompiles() { 32 needs(IsEmptyIterable.emptyIterableOf(String.class)); 33 } 34 needs(@uppressWarnings"unused") Matcher<Iterable<String>> bar)35 private void needs(@SuppressWarnings("unused") Matcher<Iterable<String>> bar) { } 36 collectionOfValues()37 private static Collection<String> collectionOfValues() { 38 return new ArrayList<String>(asList("one", "three")); 39 } 40 emptyCollection()41 private static Collection<Integer> emptyCollection() { 42 return new ArrayList<Integer>(); 43 } 44 } 45