1package org.hamcrest.collection; 2 3import org.hamcrest.AbstractMatcherTest; 4import org.hamcrest.Matcher; 5import org.hamcrest.collection.IsIterableContainingInOrderTest.WithValue; 6 7import java.util.Collections; 8 9import static java.util.Arrays.asList; 10import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; 11import static org.hamcrest.collection.IsIterableContainingInOrderTest.make; 12import static org.hamcrest.collection.IsIterableContainingInOrderTest.value; 13 14public class IsIterableContainingInAnyOrderTest extends AbstractMatcherTest { 15 16 @Override 17 protected Matcher<?> createMatcher() { 18 return containsInAnyOrder(1, 2); 19 } 20 21 public void testMatchesSingleItemIterable() { 22 assertMatches("single item", containsInAnyOrder(1), asList(1)); 23 } 24 25 public void testDoesNotMatchEmpty() { 26 assertMismatchDescription("no item matches: <1>, <2> in []", containsInAnyOrder(1, 2), Collections.<Integer>emptyList()); 27 } 28 29 public void testMatchesIterableOutOfOrder() { 30 assertMatches("Out of order", containsInAnyOrder(1, 2), asList(2, 1)); 31 } 32 33 public void testMatchesIterableInOrder() { 34 assertMatches("In order", containsInAnyOrder(1, 2), asList(1, 2)); 35 } 36 37 public void testDoesNotMatchIfOneOfMultipleElementsMismatches() { 38 assertMismatchDescription("not matched: <4>", containsInAnyOrder(1, 2, 3), asList(1, 2, 4)); 39 } 40 41 @SuppressWarnings("unchecked") 42 public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() { 43 final Matcher<Iterable<? extends WithValue>> helpTheCompilerOut = containsInAnyOrder(value(1), value(3)); 44 assertMismatchDescription("not matched: <WithValue 2>", helpTheCompilerOut, asList(make(1), make(2), make(3))); 45 } 46 47 public void testDoesNotMatchIfThereAreMoreMatchersThanElements() { 48 assertMismatchDescription("no item matches: <4> in [<1>, <2>, <3>]", containsInAnyOrder(1, 2, 3, 4), asList(1, 2, 3)); 49 } 50 51 public void testHasAReadableDescription() { 52 assertDescription("iterable with items [<1>, <2>] in any order", containsInAnyOrder(1, 2)); 53 } 54} 55