Skip to content

Commit 6472f4e

Browse files
author
smgfreeman
committed
Issue 60. IsIterableContainingInAnyOrder now accepts any number of matchers.
1 parent 658eaf8 commit 6472f4e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public class IsIterableContainingInAnyOrder<T> extends TypeSafeMatcher<Iterable<
1717
private final Collection<Matcher<? super T>> matchers;
1818

1919
public IsIterableContainingInAnyOrder(Collection<Matcher<? super T>> matchers) {
20-
if (matchers.size() < 2) {
21-
throw new IllegalArgumentException("Must specify at least two expected elements!");
22-
}
2320
this.matchers = matchers;
2421
}
2522

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ public class IsIterableContainingInAnyOrderTest extends AbstractMatcherTest {
1515
protected Matcher<?> createMatcher() {
1616
return containsInAnyOrder(1, 2);
1717
}
18-
19-
public void testDoesNotMatchEmpty() throws Exception {
18+
19+
public void testMatchesSingleItemIterable() {
20+
assertMatches("single item", containsInAnyOrder(1), asList(1));
21+
}
22+
23+
public void testDoesNotMatchEmpty() {
2024
assertMismatchDescription("iterable was []", containsInAnyOrder(1, 2), Collections.<Integer>emptyList());
2125
}
2226

23-
public void testMatchesIterableOutOfOrder() throws Exception {
27+
public void testMatchesIterableOutOfOrder() {
2428
assertMatches("Out of order", containsInAnyOrder(1, 2), asList(2, 1));
2529
}
2630

27-
public void testMatchesIterableInOrder() throws Exception {
31+
public void testMatchesIterableInOrder() {
2832
assertMatches("In order", containsInAnyOrder(1, 2), asList(1, 2));
2933
}
3034

31-
public void testDoesNotMatchIfOneOfMultipleElementsMismatches() throws Exception {
35+
public void testDoesNotMatchIfOneOfMultipleElementsMismatches() {
3236
assertMismatchDescription("iterable was [<1>, <2>, <4>]", containsInAnyOrder(1, 2, 3), asList(1, 2, 4));
3337
}
3438

35-
public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() throws Exception {
39+
public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() {
3640
assertMismatchDescription("iterable was [<1>, <2>, <3>, <4>]", containsInAnyOrder(1, 2, 3), asList(1, 2, 3, 4));
3741
}
3842

39-
public void testDoesNotMatchIfThereAreMoreMatchersThanElements() throws Exception {
43+
public void testDoesNotMatchIfThereAreMoreMatchersThanElements() {
4044
assertMismatchDescription("iterable was [<1>, <2>, <3>]", containsInAnyOrder(1, 2, 3, 4), asList(1, 2, 3));
4145
}
4246

0 commit comments

Comments
 (0)