Skip to content

Commit b3837b0

Browse files
author
smgfreeman
committed
cleaned up IsArrayContainingInAnyOrder
1 parent 3d6914a commit b3837b0

File tree

2 files changed

+32
-107
lines changed

2 files changed

+32
-107
lines changed

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -49,110 +49,10 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? su
4949

5050
@Factory
5151
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
52-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
53-
for (E item : items) {
54-
matchers.add(equalTo(item));
55-
}
56-
return new IsArrayContainingInAnyOrder<E>(matchers);
57-
}
58-
59-
@Factory
60-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E first, E second) {
61-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
62-
matchers.add(equalTo(first));
63-
matchers.add(equalTo(second));
64-
return new IsArrayContainingInAnyOrder<E>(matchers);
65-
}
66-
67-
@Factory
68-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E first, E second, E third) {
69-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
70-
matchers.add(equalTo(first));
71-
matchers.add(equalTo(second));
72-
matchers.add(equalTo(third));
73-
return new IsArrayContainingInAnyOrder<E>(matchers);
74-
}
75-
76-
@Factory
77-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E first, E second, E third, E forth) {
78-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
79-
matchers.add(equalTo(first));
80-
matchers.add(equalTo(second));
81-
matchers.add(equalTo(third));
82-
matchers.add(equalTo(forth));
83-
return new IsArrayContainingInAnyOrder<E>(matchers);
84-
}
85-
86-
@Factory
87-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E first, E second, E third, E forth, E fifth) {
88-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
89-
matchers.add(equalTo(first));
90-
matchers.add(equalTo(second));
91-
matchers.add(equalTo(third));
92-
matchers.add(equalTo(forth));
93-
matchers.add(equalTo(fifth));
94-
return new IsArrayContainingInAnyOrder<E>(matchers);
95-
}
96-
97-
@Factory
98-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E first, E second, E third, E forth, E fifth, E sixth) {
99-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
100-
matchers.add(equalTo(first));
101-
matchers.add(equalTo(second));
102-
matchers.add(equalTo(third));
103-
matchers.add(equalTo(forth));
104-
matchers.add(equalTo(fifth));
105-
matchers.add(equalTo(sixth));
106-
return new IsArrayContainingInAnyOrder<E>(matchers);
107-
}
108-
109-
@Factory
110-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<E> first, Matcher<? super E> second) {
111-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
112-
matchers.add(first);
113-
matchers.add(second);
114-
return arrayContainingInAnyOrder(matchers);
115-
}
116-
117-
@Factory
118-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third) {
119-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
120-
matchers.add(first);
121-
matchers.add(second);
122-
matchers.add(third);
123-
return arrayContainingInAnyOrder(matchers);
124-
}
125-
126-
@Factory
127-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth) {
128-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
129-
matchers.add(first);
130-
matchers.add(second);
131-
matchers.add(third);
132-
matchers.add(forth);
133-
return arrayContainingInAnyOrder(matchers);
134-
}
135-
136-
@Factory
137-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth) {
138-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
139-
matchers.add(first);
140-
matchers.add(second);
141-
matchers.add(third);
142-
matchers.add(forth);
143-
matchers.add(fifth);
144-
return arrayContainingInAnyOrder(matchers);
145-
}
146-
147-
@Factory
148-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth, Matcher<? super E> sixth) {
149-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
150-
matchers.add(first);
151-
matchers.add(second);
152-
matchers.add(third);
153-
matchers.add(forth);
154-
matchers.add(fifth);
155-
matchers.add(sixth);
156-
return arrayContainingInAnyOrder(matchers);
52+
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
53+
for (E item : items) {
54+
matchers.add(equalTo(item));
55+
}
56+
return new IsArrayContainingInAnyOrder<E>(matchers);
15757
}
15858
}

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,38 @@
88

99
public class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest {
1010

11+
@SuppressWarnings("unchecked")
1112
@Override
1213
protected Matcher<?> createMatcher() {
1314
return arrayContainingInAnyOrder(equalTo(1), equalTo(2));
1415
}
1516

17+
@SuppressWarnings("unchecked")
1618
public void testHasAReadableDescription() {
17-
assertDescription("[<<1>>, <<2>>] in any order",
18-
arrayContainingInAnyOrder(equalTo(1), equalTo(2)));
19+
assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(equalTo(1), equalTo(2)));
20+
assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(1, 2));
1921
}
22+
23+
public void testMatchesItemsInAnyOrder() {
24+
assertMatches("in order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3});
25+
assertMatches("out of order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1});
26+
assertMatches("single", arrayContainingInAnyOrder(1), new Integer[] {1});
27+
}
28+
29+
@SuppressWarnings("unchecked")
30+
public void testAppliesMatchersInAnyOrder() {
31+
assertMatches("in order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3});
32+
assertMatches("out of order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1});
33+
assertMatches("single", arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1});
34+
}
35+
36+
public void testMismatchesItemsInAnyOrder() {
37+
Matcher<Integer[]> matcher = arrayContainingInAnyOrder(1, 2, 3);
38+
assertMismatchDescription("was null", matcher, null);
39+
assertMismatchDescription("No item matches: <1>, <2>, <3> in []", matcher, new Integer[] {});
40+
assertMismatchDescription("No item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1});
41+
assertMismatchDescription("Not matched: <4>", matcher, new Integer[] {4,3,2,1});
42+
}
43+
44+
2045
}

0 commit comments

Comments
 (0)