44import org .hamcrest .Matcher ;
55import org .hamcrest .TypeSafeMatcher ;
66
7- import java .util .ArrayList ;
87import java .util .Arrays ;
98import java .util .Collection ;
10- import java .util .List ;
11-
12- import static org .hamcrest .core .IsEqual .equalTo ;
139
1410public class IsArrayContainingInAnyOrder <E > extends TypeSafeMatcher <E []> {
1511 private final IsIterableContainingInAnyOrder <E > iterableMatcher ;
@@ -35,80 +31,4 @@ public void describeTo(Description description) {
3531 description .appendList ("[" , ", " , "]" , matchers )
3632 .appendText (" in any order" );
3733 }
38-
39- /**
40- * <p>
41- * Creates an order agnostic matcher for arrays that matches when each item in the
42- * examined array satisfies one matcher anywhere in the specified matchers.
43- * For a positive match, the examined array must be of the same length as the number of
44- * specified matchers.
45- * </p>
46- * <p>
47- * N.B. each of the specified matchers will only be used once during a given examination, so be
48- * careful when specifying matchers that may be satisfied by more than one entry in an examined
49- * array.
50- * </p>
51- * <p>
52- * For example:
53- * </p>
54- * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre>
55- *
56- * @param itemMatchers
57- * a list of matchers, each of which must be satisfied by an entry in an examined array
58- */
59- @ SafeVarargs
60- public static <E > Matcher <E []> arrayContainingInAnyOrder (Matcher <? super E >... itemMatchers ) {
61- return arrayContainingInAnyOrder (Arrays .asList (itemMatchers ));
62- }
63-
64- /**
65- * <p>
66- * Creates an order agnostic matcher for arrays that matches when each item in the
67- * examined array satisfies one matcher anywhere in the specified collection of matchers.
68- * For a positive match, the examined array must be of the same length as the specified collection
69- * of matchers.
70- * </p>
71- * <p>
72- * N.B. each matcher in the specified collection will only be used once during a given
73- * examination, so be careful when specifying matchers that may be satisfied by more than
74- * one entry in an examined array.
75- * </p>
76- * <p>
77- * For example:
78- * </p>
79- * <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))</pre>
80- *
81- * @param itemMatchers
82- * a list of matchers, each of which must be satisfied by an item provided by an examined array
83- */
84- public static <E > Matcher <E []> arrayContainingInAnyOrder (Collection <Matcher <? super E >> itemMatchers ) {
85- return new IsArrayContainingInAnyOrder <>(itemMatchers );
86- }
87-
88- /**
89- * <p>Creates an order agnostic matcher for arrays that matches when each item in the
90- * examined array is logically equal to one item anywhere in the specified items.
91- * For a positive match, the examined array must be of the same length as the number of
92- * specified items.
93- * </p>
94- * <p>N.B. each of the specified items will only be used once during a given examination, so be
95- * careful when specifying items that may be equal to more than one entry in an examined
96- * array.
97- * </p>
98- * <p>
99- * For example:
100- * </p>
101- * <pre>assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))</pre>
102- *
103- * @param items
104- * the items that must equal the entries of an examined array, in any order
105- */
106- @ SafeVarargs
107- public static <E > Matcher <E []> arrayContainingInAnyOrder (E ... items ) {
108- List <Matcher <? super E >> matchers = new ArrayList <>();
109- for (E item : items ) {
110- matchers .add (equalTo (item ));
111- }
112- return new IsArrayContainingInAnyOrder <>(matchers );
113- }
11434}
0 commit comments