33import org .hamcrest .Description ;
44import org .hamcrest .Matcher ;
55import org .hamcrest .TypeSafeMatcher ;
6- import org .hamcrest .internal .Wrapping ;
76
8- import java .util .ArrayList ;
97import java .util .Collection ;
108import java .util .List ;
119
1210import static java .util .Arrays .asList ;
13- import static org .hamcrest .core .IsEqual .equalTo ;
1411
1512public class IsArrayContainingInOrder <E > extends TypeSafeMatcher <E []> {
1613 private final Collection <Matcher <? super E >> matchers ;
@@ -35,53 +32,4 @@ public void describeMismatchSafely(E[] item, Description mismatchDescription) {
3532 public void describeTo (Description description ) {
3633 description .appendList ("[" , ", " , "]" , matchers );
3734 }
38-
39- /**
40- * Creates a matcher for arrays that matches when each item in the examined array is
41- * logically equal to the corresponding item in the specified items. For a positive match,
42- * the examined array must be of the same length as the number of specified items.
43- * For example:
44- * <pre>assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))</pre>
45- *
46- * @param items
47- * the items that must equal the items within an examined array
48- */
49- @ SafeVarargs
50- public static <E > Matcher <E []> arrayContaining (E ... items ) {
51- List <Matcher <? super E >> matchers = new ArrayList <>();
52- for (E item : items ) {
53- matchers .add (equalTo (item ));
54- }
55- return arrayContaining (matchers );
56- }
57-
58- /**
59- * Creates a matcher for arrays that matches when each item in the examined array satisfies the
60- * corresponding matcher in the specified matchers. For a positive match, the examined array
61- * must be of the same length as the number of specified matchers.
62- * For example:
63- * <pre>assertThat(new String[]{"foo", "bar"}, contains(equalTo("foo"), equalTo("bar")))</pre>
64- *
65- * @param itemMatchers
66- * the matchers that must be satisfied by the items in the examined array
67- */
68- @ SafeVarargs
69- public static <E > Matcher <E []> arrayContaining (Matcher <? super E >... itemMatchers ) {
70- return arrayContaining (Wrapping .nullSafe (itemMatchers ));
71- }
72-
73- /**
74- * Creates a matcher for arrays that matches when each item in the examined array satisfies the
75- * corresponding matcher in the specified list of matchers. For a positive match, the examined array
76- * must be of the same length as the specified list of matchers.
77- * For example:
78- * <pre>assertThat(new String[]{"foo", "bar"}, contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))</pre>
79- *
80- * @param itemMatchers
81- * a list of matchers, each of which must be satisfied by the corresponding item in an examined array
82- */
83- public static <E > Matcher <E []> arrayContaining (List <Matcher <? super E >> itemMatchers ) {
84- return new IsArrayContainingInOrder <>(itemMatchers );
85- }
86-
8735}
0 commit comments