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