Skip to content

Commit d4e6adf

Browse files
committed
Factory methods. Oops. Should have been MatchIterables.
1 parent 38c7a68 commit d4e6adf

File tree

3 files changed

+17
-73
lines changed

3 files changed

+17
-73
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items) {
541541
* @param itemMatchers the matchers that must be satisfied by the items in the examined array
542542
*/
543543
@SafeVarargs
544-
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher<? super E>... itemMatchers) {
544+
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers) {
545545
return MatchArrays.arrayContaining(itemMatchers);
546546
}
547547

@@ -554,7 +554,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher
554554
*
555555
* @param itemMatchers a list of matchers, each of which must be satisfied by the corresponding item in an examined array
556556
*/
557-
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) {
557+
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<Matcher<? super E>> itemMatchers) {
558558
return MatchArrays.arrayContaining(itemMatchers);
559559
}
560560

@@ -578,7 +578,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.h
578578
* @param itemMatchers a list of matchers, each of which must be satisfied by an entry in an examined array
579579
*/
580580
@SafeVarargs
581-
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcrest.Matcher<? super E>... itemMatchers) {
581+
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) {
582582
return MatchArrays.arrayContainingInAnyOrder(itemMatchers);
583583
}
584584

@@ -601,7 +601,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcre
601601
*
602602
* @param itemMatchers a list of matchers, each of which must be satisfied by an item provided by an examined array
603603
*/
604-
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<org.hamcrest.Matcher<? super E>> itemMatchers) {
604+
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<Matcher<? super E>> itemMatchers) {
605605
return MatchArrays.arrayContainingInAnyOrder(itemMatchers);
606606
}
607607

@@ -773,7 +773,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<E>> emptyIterableOf(ja
773773
*/
774774
@SafeVarargs
775775
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(E... items) {
776-
return MatchCollections.contains(items);
776+
return MatchIterables.contains(items);
777777
}
778778

779779
/**
@@ -786,8 +786,8 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
786786
* @param itemMatcher the matcher that must be satisfied by the single item provided by an
787787
* examined {@link Iterable}
788788
*/
789-
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(org.hamcrest.Matcher<? super E> itemMatcher) {
790-
return MatchCollections.contains(itemMatcher);
789+
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E> itemMatcher) {
790+
return MatchIterables.contains(itemMatcher);
791791
}
792792

793793
/**
@@ -801,8 +801,8 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
801801
* @param itemMatchers the matchers that must be satisfied by the items provided by an examined {@link Iterable}
802802
*/
803803
@SafeVarargs
804-
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(org.hamcrest.Matcher<? super E>... itemMatchers) {
805-
return MatchCollections.contains(itemMatchers);
804+
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers) {
805+
return MatchIterables.contains(itemMatchers);
806806
}
807807

808808
/**
@@ -816,8 +816,8 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
816816
* @param itemMatchers a list of matchers, each of which must be satisfied by the corresponding item provided by
817817
* an examined {@link Iterable}
818818
*/
819-
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) {
820-
return MatchCollections.contains(itemMatchers);
819+
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains(java.util.List<Matcher<? super E>> itemMatchers) {
820+
return MatchIterables.contains(itemMatchers);
821821
}
822822

823823
/**
@@ -913,7 +913,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
913913
* @param itemMatchers the matchers that must be satisfied by the items provided by an examined {@link Iterable} in the same relative order
914914
*/
915915
@SafeVarargs
916-
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(org.hamcrest.Matcher<? super E>... itemMatchers) {
916+
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(Matcher<? super E>... itemMatchers) {
917917
return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers);
918918
}
919919

@@ -927,7 +927,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
927927
* @param itemMatchers a list of matchers, each of which must be satisfied by the items provided by
928928
* an examined {@link Iterable} in the same relative order
929929
*/
930-
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) {
930+
public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> containsInRelativeOrder(java.util.List<Matcher<? super E>> itemMatchers) {
931931
return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers);
932932
}
933933

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import org.hamcrest.Description;
44
import org.hamcrest.Matcher;
55
import org.hamcrest.TypeSafeDiagnosingMatcher;
6+
import org.hamcrest.internal.Wrapping;
67

78
import java.util.ArrayList;
8-
import java.util.Arrays;
99
import java.util.Collection;
10-
import java.util.List;
1110

12-
import static org.hamcrest.core.IsEqual.equalTo;
11+
import static java.util.Arrays.asList;
1312

1413
public class IsIterableContainingInAnyOrder<T> extends TypeSafeDiagnosingMatcher<Iterable<? extends T>> {
1514
private final Collection<Matcher<? super T>> matchers;
@@ -98,7 +97,7 @@ private boolean isMatched(S item) {
9897
*/
9998
@SafeVarargs
10099
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers) {
101-
return containsInAnyOrder(Arrays.asList(itemMatchers));
100+
return containsInAnyOrder(asList(itemMatchers));
102101
}
103102

104103
/**
@@ -123,12 +122,7 @@ public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? su
123122
*/
124123
@SafeVarargs
125124
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(T... items) {
126-
List<Matcher<? super T>> matchers = new ArrayList<>();
127-
for (T item : items) {
128-
matchers.add(equalTo(item));
129-
}
130-
131-
return new IsIterableContainingInAnyOrder<>(matchers);
125+
return new IsIterableContainingInAnyOrder<>(Wrapping.asEqualToMatchers(items));
132126
}
133127

134128
/**
Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.hamcrest.collection;
22

33
import org.hamcrest.Matcher;
4-
import org.hamcrest.internal.Wrapping;
54

65
import java.util.Collection;
7-
import java.util.List;
86

97
import static org.hamcrest.object.MatchObjects.equalTo;
108

@@ -58,52 +56,4 @@ public static <E> Matcher<Collection<? extends E>> empty() {
5856
public static <E> Matcher<Collection<E>> emptyCollectionOf(Class<E> unusedToForceReturnType) {
5957
return (Matcher)empty();
6058
}
61-
62-
/**
63-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
64-
* examined {@link Iterable} yields a series of items, each logically equal to the
65-
* corresponding item in the specified items. For a positive match, the examined iterable
66-
* must be of the same length as the number of specified items.
67-
* For example:
68-
* <pre>assertThat(Arrays.asList("foo", "bar"), contains("foo", "bar"))</pre>
69-
*
70-
* @param items
71-
* the items that must equal the items provided by an examined {@link Iterable}
72-
*/
73-
@SafeVarargs
74-
public static <E> Matcher<Iterable<? extends E>> contains(E... items) {
75-
return contains(Wrapping.asEqualToMatchers(items));
76-
}
77-
78-
/**
79-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
80-
* examined {@link Iterable} yields a series of items, each satisfying the corresponding
81-
* matcher in the specified matchers. For a positive match, the examined iterable
82-
* must be of the same length as the number of specified matchers.
83-
* For example:
84-
* <pre>assertThat(Arrays.asList("foo", "bar"), contains(equalTo("foo"), equalTo("bar")))</pre>
85-
*
86-
* @param itemMatchers
87-
* the matchers that must be satisfied by the items provided by an examined {@link Iterable}
88-
*/
89-
@SafeVarargs
90-
public static <E> Matcher<Iterable<? extends E>> contains(Matcher<? super E>... itemMatchers) {
91-
return contains(Wrapping.nullSafe(itemMatchers));
92-
}
93-
94-
/**
95-
* Creates a matcher for {@link Iterable}s that matches when a single pass over the
96-
* examined {@link Iterable} yields a series of items, each satisfying the corresponding
97-
* matcher in the specified list of matchers. For a positive match, the examined iterable
98-
* must be of the same length as the specified list of matchers.
99-
* For example:
100-
* <pre>assertThat(Arrays.asList("foo", "bar"), contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))</pre>
101-
*
102-
* @param itemMatchers
103-
* a list of matchers, each of which must be satisfied by the corresponding item provided by
104-
* an examined {@link Iterable}
105-
*/
106-
public static <E> Matcher<Iterable<? extends E>> contains(List<Matcher<? super E>> itemMatchers) {
107-
return new IsIterableContainingInOrder<>(itemMatchers);
108-
}
10959
}

0 commit comments

Comments
 (0)