1 package org.hamcrest.collection; 2 3 import org.hamcrest.AbstractMatcherTest; 4 import org.hamcrest.Matcher; 5 6 import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining; 7 import static org.hamcrest.core.IsEqual.equalTo; 8 9 public class IsArrayContainingInOrderTest extends AbstractMatcherTest { 10 11 @SuppressWarnings("unchecked") 12 @Override 13 protected Matcher<?> createMatcher() { 14 return arrayContaining(equalTo(1), equalTo(2)); 15 } 16 17 @SuppressWarnings("unchecked") 18 public void testHasAReadableDescription() { 19 assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2))); 20 } 21 22 public void testMatchesItemsInOrder() { 23 assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); 24 assertMatches("single", arrayContaining(1), new Integer[] {1}); 25 } 26 27 @SuppressWarnings("unchecked") 28 public void testAppliesMatchersInOrder() { 29 assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); 30 assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); 31 } 32 33 public void testMismatchesItemsInOrder() { 34 Matcher<Integer[]> matcher = arrayContaining(1, 2, 3); 35 assertMismatchDescription("was null", matcher, null); 36 assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); 37 assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); 38 assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); 39 assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); 40 } 41 42 public void testCanHandleNullValuesInAnArray() { 43 assertMatches("with nulls", arrayContaining(null, null), new Object[]{null, null}); 44 } 45 } 46