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.IsEmptyCollection.empty; 11 import static org.hamcrest.core.Is.is; 12 13 public class IsEmptyCollectionTest extends AbstractMatcherTest { 14 15 @Override createMatcher()16 protected Matcher<Collection<?>> createMatcher() { 17 return empty(); 18 } 19 testMatchesAnEmptyCollection()20 public void testMatchesAnEmptyCollection() { 21 assertMatches("empty collection", createMatcher(), emptyCollection()); 22 } 23 testDoesNotMatchACollectionWithAnItem()24 public void testDoesNotMatchACollectionWithAnItem() { 25 assertMismatchDescription("<[one, three]>", is(createMatcher()), collectionOfValues()); 26 } 27 testHasAReadableDescription()28 public void testHasAReadableDescription() { 29 assertDescription("an empty collection", createMatcher()); 30 } 31 testCompiles()32 public void testCompiles() { 33 needs(IsEmptyCollection.emptyCollectionOf(String.class)); 34 } 35 needs(@uppressWarnings"unused") Matcher<Collection<String>> bar)36 private void needs(@SuppressWarnings("unused") Matcher<Collection<String>> bar) { } 37 collectionOfValues()38 private static Collection<String> collectionOfValues() { 39 return new ArrayList<String>(asList("one", "three")); 40 } 41 emptyCollection()42 private static Collection<Integer> emptyCollection() { 43 return new ArrayList<Integer>(); 44 } 45 } 46