Skip to content

Commit 0dd0797

Browse files
committed
Factory methods for IsIterableWithSize
1 parent f54712c commit 0dd0797

File tree

4 files changed

+6
-33
lines changed

4 files changed

+6
-33
lines changed

hamcrest-library/src/main/java/org/hamcrest/Matchers.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hamcrest;
22

33
import org.hamcrest.collection.MatchArrays;
4+
import org.hamcrest.collection.MatchIterables;
45
import org.hamcrest.number.MatchNumbers;
56
import org.hamcrest.object.MatchObjects;
67
import org.hamcrest.text.MatchStrings;
@@ -939,7 +940,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
939940
* @param sizeMatcher a matcher for the number of items that should be yielded by an examined {@link Iterable}
940941
*/
941942
public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher) {
942-
return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(sizeMatcher);
943+
return MatchIterables.iterableWithSize(sizeMatcher);
943944
}
944945

945946
/**
@@ -952,7 +953,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(o
952953
* @param size the number of items that should be yielded by an examined {@link Iterable}
953954
*/
954955
public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> iterableWithSize(int size) {
955-
return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(size);
956+
return MatchIterables.iterableWithSize(size);
956957
}
957958

958959
/**

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import java.util.Iterator;
77

8-
import static org.hamcrest.core.IsEqual.equalTo;
9-
108
public class IsIterableWithSize<E> extends FeatureMatcher<Iterable<E>, Integer> {
119

1210
public IsIterableWithSize(Matcher<? super Integer> sizeMatcher) {
@@ -23,31 +21,4 @@ protected Integer featureValueOf(Iterable<E> actual) {
2321
return size;
2422
}
2523

26-
/**
27-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
28-
* examined {@link Iterable} yields an item count that satisfies the specified
29-
* matcher.
30-
* For example:
31-
* <pre>assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))</pre>
32-
*
33-
* @param sizeMatcher
34-
* a matcher for the number of items that should be yielded by an examined {@link Iterable}
35-
*/
36-
public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer> sizeMatcher) {
37-
return new IsIterableWithSize<>(sizeMatcher);
38-
}
39-
40-
/**
41-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
42-
* examined {@link Iterable} yields an item count that is equal to the specified
43-
* <code>size</code> argument.
44-
* For example:
45-
* <pre>assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))</pre>
46-
*
47-
* @param size
48-
* the number of items that should be yielded by an examined {@link Iterable}
49-
*/
50-
public static <E> Matcher<Iterable<E>> iterableWithSize(int size) {
51-
return iterableWithSize(equalTo(size));
52-
}
5324
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer>
358358
* @param size the number of items that should be yielded by an examined {@link Iterable}
359359
*/
360360
public static <E> Matcher<Iterable<E>> iterableWithSize(int size) {
361-
return IsIterableWithSize.iterableWithSize(equalTo(size));
361+
return iterableWithSize(equalTo(size));
362362
}
363363

364364
public static <T> Matcher<Iterable<? extends T>> hasSubsequence(List<Matcher<? super T>> matchers) {

hamcrest-library/src/test/java/org/hamcrest/collection/IsIterableWithSizeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import java.util.Arrays;
77
import java.util.Collections;
88

9-
import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize;
9+
import static org.hamcrest.collection.MatchIterables.iterableWithSize;
10+
1011

1112
public class IsIterableWithSizeTest extends AbstractMatcherTest {
1213

0 commit comments

Comments
 (0)