diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java index dfb9d128..180a4f76 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java @@ -57,9 +57,6 @@ private static class MatchSeries { public MatchSeries(List> matchers, Description mismatchDescription) { this.mismatchDescription = mismatchDescription; - if (matchers.isEmpty()) { - throw new IllegalArgumentException("Should specify at least one expected element"); - } this.matchers = matchers; } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java index bc318bb1..7a602202 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.hamcrest.test.MatcherAssertions.*; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; @@ -24,6 +25,31 @@ protected Matcher createMatcher() { return contains(1, 2); } + @Test + public void testMatchingEmptyIterableWithNoExpectedItems() { + assertMatches(contains(new String[0]), emptyList()); + } + + @Test + public void testMatchingEmptyIterableWithNoExpectedMatchers() { + assertMatches(contains(new Matcher[0]), emptyList()); + } + + @Test + public void testMatchingEmptyIterableWithEmptyMatcherList() { + assertMatches(contains(emptyList()), emptyList()); + } + + @Test + public void testDoesNotMatchNonEmptyIterableWithNoExpectedItems() { + assertMismatchDescription("not matched: <1>", contains(new Integer[0]), singletonList(1)); + } + + @Test + public void testHasAReadableDescriptionWithNoExpectedItems() { + assertDescription("iterable containing []", contains(new Integer[0])); + } + @Test public void testMatchingSingleItemIterable() throws Exception { assertMatches("Single item iterable", contains(1), singletonList(1));