Skip to content

Commit 5e0cb5c

Browse files
author
smgfreeman
committed
cleaned up other collection matchers
1 parent b3837b0 commit 5e0cb5c

File tree

7 files changed

+27
-304
lines changed

7 files changed

+27
-304
lines changed

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

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -44,56 +44,6 @@ public static <E> Matcher<E[]> arrayContaining(E... items) {
4444
return arrayContaining(matchers);
4545
}
4646

47-
@Factory
48-
public static <E> Matcher<E[]> arrayContaining(E first, E second) {
49-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
50-
matchers.add(equalTo(first));
51-
matchers.add(equalTo(second));
52-
return arrayContaining(matchers);
53-
}
54-
55-
@Factory
56-
public static <E> Matcher<E[]> arrayContaining(E first, E second, E third) {
57-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
58-
matchers.add(equalTo(first));
59-
matchers.add(equalTo(second));
60-
matchers.add(equalTo(third));
61-
return arrayContaining(matchers);
62-
}
63-
64-
@Factory
65-
public static <E> Matcher<E[]> arrayContaining(E first, E second, E third, E forth) {
66-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
67-
matchers.add(equalTo(first));
68-
matchers.add(equalTo(second));
69-
matchers.add(equalTo(third));
70-
matchers.add(equalTo(forth));
71-
return arrayContaining(matchers);
72-
}
73-
74-
@Factory
75-
public static <E> Matcher<E[]> arrayContaining(E first, E second, E third, E forth, E fifth) {
76-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
77-
matchers.add(equalTo(first));
78-
matchers.add(equalTo(second));
79-
matchers.add(equalTo(third));
80-
matchers.add(equalTo(forth));
81-
matchers.add(equalTo(fifth));
82-
return arrayContaining(matchers);
83-
}
84-
85-
@Factory
86-
public static <E> Matcher<E[]> arrayContaining(E first, E second, E third, E forth, E fifth, E sixth) {
87-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
88-
matchers.add(equalTo(first));
89-
matchers.add(equalTo(second));
90-
matchers.add(equalTo(third));
91-
matchers.add(equalTo(forth));
92-
matchers.add(equalTo(fifth));
93-
matchers.add(equalTo(sixth));
94-
return arrayContaining(matchers);
95-
}
96-
9747
@Factory
9848
public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... matchers) {
9949
return arrayContaining(Arrays.asList(matchers));
@@ -103,54 +53,4 @@ public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... matchers) {
10353
public static <E> Matcher<E[]> arrayContaining(List<Matcher<? super E>> matchers) {
10454
return new IsArrayContainingInOrder<E>(matchers);
10555
}
106-
107-
@Factory
108-
public static <E> Matcher<E[]> arrayContaining(Matcher<E> first, Matcher<? super E> second) {
109-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
110-
matchers.add(first);
111-
matchers.add(second);
112-
return arrayContaining(matchers);
113-
}
114-
115-
@Factory
116-
public static <E> Matcher<E[]> arrayContaining(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third) {
117-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
118-
matchers.add(first);
119-
matchers.add(second);
120-
matchers.add(third);
121-
return arrayContaining(matchers);
122-
}
123-
124-
@Factory
125-
public static <E> Matcher<E[]> arrayContaining(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth) {
126-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
127-
matchers.add(first);
128-
matchers.add(second);
129-
matchers.add(third);
130-
matchers.add(forth);
131-
return arrayContaining(matchers);
132-
}
133-
134-
@Factory
135-
public static <E> Matcher<E[]> arrayContaining(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth) {
136-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
137-
matchers.add(first);
138-
matchers.add(second);
139-
matchers.add(third);
140-
matchers.add(forth);
141-
matchers.add(fifth);
142-
return arrayContaining(matchers);
143-
}
144-
145-
@Factory
146-
public static <E> Matcher<E[]> arrayContaining(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth, Matcher<? super E> sixth) {
147-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
148-
matchers.add(first);
149-
matchers.add(second);
150-
matchers.add(third);
151-
matchers.add(forth);
152-
matchers.add(fifth);
153-
matchers.add(sixth);
154-
return arrayContaining(matchers);
155-
}
15656
}

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

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -100,106 +100,6 @@ public static <T> Matcher<Iterable<T>> containsInAnyOrder(T... items) {
100100
return new IsIterableContainingInAnyOrder<T>(matchers);
101101
}
102102

103-
@Factory
104-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(T first, T second) {
105-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
106-
matchers.add(equalTo(first));
107-
matchers.add(equalTo(second));
108-
return containsInAnyOrder(matchers);
109-
}
110-
111-
@Factory
112-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(T first, T second, T third) {
113-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
114-
matchers.add(equalTo(first));
115-
matchers.add(equalTo(second));
116-
matchers.add(equalTo(third));
117-
return containsInAnyOrder(matchers);
118-
}
119-
120-
@Factory
121-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(T first, T second, T third, T forth) {
122-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
123-
matchers.add(equalTo(first));
124-
matchers.add(equalTo(second));
125-
matchers.add(equalTo(third));
126-
matchers.add(equalTo(forth));
127-
return containsInAnyOrder(matchers);
128-
}
129-
130-
@Factory
131-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(T first, T second, T third, T forth, T fifth) {
132-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
133-
matchers.add(equalTo(first));
134-
matchers.add(equalTo(second));
135-
matchers.add(equalTo(third));
136-
matchers.add(equalTo(forth));
137-
matchers.add(equalTo(fifth));
138-
return containsInAnyOrder(matchers);
139-
}
140-
141-
@Factory
142-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(T first, T second, T third, T forth, T fifth, T sixth) {
143-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
144-
matchers.add(equalTo(first));
145-
matchers.add(equalTo(second));
146-
matchers.add(equalTo(third));
147-
matchers.add(equalTo(forth));
148-
matchers.add(equalTo(fifth));
149-
matchers.add(equalTo(sixth));
150-
return containsInAnyOrder(matchers);
151-
}
152-
153-
@Factory
154-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<T> first, Matcher<? super T> second) {
155-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
156-
matchers.add(first);
157-
matchers.add(second);
158-
return containsInAnyOrder(matchers);
159-
}
160-
161-
@Factory
162-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third) {
163-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
164-
matchers.add(first);
165-
matchers.add(second);
166-
matchers.add(third);
167-
return containsInAnyOrder(matchers);
168-
}
169-
170-
@Factory
171-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> forth) {
172-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
173-
matchers.add(first);
174-
matchers.add(second);
175-
matchers.add(third);
176-
matchers.add(forth);
177-
return containsInAnyOrder(matchers);
178-
}
179-
180-
@Factory
181-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> forth, Matcher<? super T> fifth) {
182-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
183-
matchers.add(first);
184-
matchers.add(second);
185-
matchers.add(third);
186-
matchers.add(forth);
187-
matchers.add(fifth);
188-
return containsInAnyOrder(matchers);
189-
}
190-
191-
@Factory
192-
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> forth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
193-
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
194-
matchers.add(first);
195-
matchers.add(second);
196-
matchers.add(third);
197-
matchers.add(forth);
198-
matchers.add(fifth);
199-
matchers.add(sixth);
200-
return containsInAnyOrder(matchers);
201-
}
202-
203103
@Factory
204104
public static <T> Matcher<Iterable<T>> containsInAnyOrder(Collection<Matcher<? super T>> matchers) {
205105
return new IsIterableContainingInAnyOrder<T>(matchers);

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

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,6 @@ public static <E> Matcher<Iterable<E>> contains(E... items) {
9292
return contains(matchers);
9393
}
9494

95-
@Factory
96-
public static <E> Matcher<Iterable<E>> contains(E first, E second) {
97-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
98-
matchers.add(equalTo(first));
99-
matchers.add(equalTo(second));
100-
return contains(matchers);
101-
}
102-
103-
@Factory
104-
public static <E> Matcher<Iterable<E>> contains(E first, E second, E third) {
105-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
106-
matchers.add(equalTo(first));
107-
matchers.add(equalTo(second));
108-
matchers.add(equalTo(third));
109-
return contains(matchers);
110-
}
111-
112-
@Factory
113-
public static <E> Matcher<Iterable<E>> contains(E first, E second, E third, E forth) {
114-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
115-
matchers.add(equalTo(first));
116-
matchers.add(equalTo(second));
117-
matchers.add(equalTo(third));
118-
matchers.add(equalTo(forth));
119-
return contains(matchers);
120-
}
121-
122-
@Factory
123-
public static <E> Matcher<Iterable<E>> contains(E first, E second, E third, E forth, E fifth) {
124-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
125-
matchers.add(equalTo(first));
126-
matchers.add(equalTo(second));
127-
matchers.add(equalTo(third));
128-
matchers.add(equalTo(forth));
129-
matchers.add(equalTo(fifth));
130-
return contains(matchers);
131-
}
132-
133-
@Factory
134-
public static <E> Matcher<Iterable<E>> contains(E first, E second, E third, E forth, E fifth, E sixth) {
135-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
136-
matchers.add(equalTo(first));
137-
matchers.add(equalTo(second));
138-
matchers.add(equalTo(third));
139-
matchers.add(equalTo(forth));
140-
matchers.add(equalTo(fifth));
141-
matchers.add(equalTo(sixth));
142-
return contains(matchers);
143-
}
144-
14595
@Factory
14696
public static <E> Matcher<Iterable<E>> contains(final Matcher<E> item) {
14797
return contains(new ArrayList<Matcher<? super E>>() {{ add(item); }});
@@ -152,56 +102,6 @@ public static <E> Matcher<Iterable<E>> contains(Matcher<? super E>... items) {
152102
return contains(Arrays.asList(items));
153103
}
154104

155-
@Factory
156-
public static <E> Matcher<Iterable<E>> contains(Matcher<E> first, Matcher<? super E> second) {
157-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
158-
matchers.add(first);
159-
matchers.add(second);
160-
return contains(matchers);
161-
}
162-
163-
@Factory
164-
public static <E> Matcher<Iterable<E>> contains(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third) {
165-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
166-
matchers.add(first);
167-
matchers.add(second);
168-
matchers.add(third);
169-
return contains(matchers);
170-
}
171-
172-
@Factory
173-
public static <E> Matcher<Iterable<E>> contains(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth) {
174-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
175-
matchers.add(first);
176-
matchers.add(second);
177-
matchers.add(third);
178-
matchers.add(forth);
179-
return contains(matchers);
180-
}
181-
182-
@Factory
183-
public static <E> Matcher<Iterable<E>> contains(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth) {
184-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
185-
matchers.add(first);
186-
matchers.add(second);
187-
matchers.add(third);
188-
matchers.add(forth);
189-
matchers.add(fifth);
190-
return contains(matchers);
191-
}
192-
193-
@Factory
194-
public static <E> Matcher<Iterable<E>> contains(Matcher<E> first, Matcher<? super E> second, Matcher<? super E> third, Matcher<? super E> forth, Matcher<? super E> fifth, Matcher<? super E> sixth) {
195-
List<Matcher<? super E>> matchers = new ArrayList<Matcher<? super E>>();
196-
matchers.add(first);
197-
matchers.add(second);
198-
matchers.add(third);
199-
matchers.add(forth);
200-
matchers.add(fifth);
201-
matchers.add(sixth);
202-
return contains(matchers);
203-
}
204-
205105
@Factory
206106
public static <E> Matcher<Iterable<E>> contains(List<Matcher<? super E>> contents) {
207107
return new IsIterableContainingInOrder<E>(contents);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ public void testMismatchesItemsInAnyOrder() {
4040
assertMismatchDescription("No item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1});
4141
assertMismatchDescription("Not matched: <4>", matcher, new Integer[] {4,3,2,1});
4242
}
43-
44-
4543
}
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.hamcrest.collection;
22

3+
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
34
import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
45
import static org.hamcrest.core.IsEqual.equalTo;
56

@@ -8,13 +9,34 @@
89

910
public class IsArrayContainingInOrderTest extends AbstractMatcherTest {
1011

12+
@SuppressWarnings("unchecked")
1113
@Override
1214
protected Matcher<?> createMatcher() {
1315
return arrayContaining(equalTo(1), equalTo(2));
1416
}
1517

18+
@SuppressWarnings("unchecked")
1619
public void testHasAReadableDescription() {
17-
assertDescription("[<<1>>, <<2>>]",
18-
arrayContaining(equalTo(1), equalTo(2)));
20+
assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2)));
21+
}
22+
23+
public void testMatchesItemsInOrder() {
24+
assertMatches("in order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3});
25+
assertMatches("single", arrayContainingInAnyOrder(1), new Integer[] {1});
26+
}
27+
28+
@SuppressWarnings("unchecked")
29+
public void testAppliesMatchersInAnyOrder() {
30+
assertMatches("in order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3});
31+
assertMatches("single", arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1});
32+
}
33+
34+
public void testMismatchesItemsInAnyOrder() {
35+
Matcher<Integer[]> matcher = arrayContainingInAnyOrder(1, 2, 3);
36+
assertMismatchDescription("was null", matcher, null);
37+
assertMismatchDescription("No item matches: <1>, <2>, <3> in []", matcher, new Integer[] {});
38+
assertMismatchDescription("No item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1});
39+
assertMismatchDescription("Not matched: <4>", matcher, new Integer[] {4,3,2,1});
40+
assertMismatchDescription("Not matched: <4>", matcher, new Integer[] {1,2, 4});
1941
}
2042
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void testDoesNotMatchIfOneOfMultipleElementsMismatches() {
3737
assertMismatchDescription("Not matched: <4>", containsInAnyOrder(1, 2, 3), asList(1, 2, 4));
3838
}
3939

40+
@SuppressWarnings("unchecked")
4041
public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() {
4142
assertMismatchDescription("Not matched: <WithValue 2>", containsInAnyOrder(value(1), value(3)), asList(make(1), make(2), make(3)));
4243
}

0 commit comments

Comments
 (0)