Skip to content

Commit ee836b8

Browse files
committed
Factory methods. Iterables contains in any order
1 parent d4e6adf commit ee836b8

File tree

3 files changed

+4
-79
lines changed

3 files changed

+4
-79
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public static <E> org.hamcrest.Matcher<java.lang.Iterable<? extends E>> contains
841841
*/
842842
@SafeVarargs
843843
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(org.hamcrest.Matcher<? super T>... itemMatchers) {
844-
return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers);
844+
return MatchIterables.containsInAnyOrder(itemMatchers);
845845
}
846846

847847
/**
@@ -865,7 +865,7 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> contains
865865
*/
866866
@SafeVarargs
867867
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(T... items) {
868-
return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(items);
868+
return MatchIterables.containsInAnyOrder(items);
869869
}
870870

871871
/**
@@ -886,7 +886,7 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> contains
886886
* @param itemMatchers a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable}
887887
*/
888888
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? extends T>> containsInAnyOrder(java.util.Collection<org.hamcrest.Matcher<? super T>> itemMatchers) {
889-
return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers);
889+
return MatchIterables.containsInAnyOrder(itemMatchers);
890890
}
891891

892892
/**

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

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

87
import java.util.ArrayList;
98
import java.util.Collection;
109

11-
import static java.util.Arrays.asList;
12-
1310
public class IsIterableContainingInAnyOrder<T> extends TypeSafeDiagnosingMatcher<Iterable<? extends T>> {
1411
private final Collection<Matcher<? super T>> matchers;
1512

@@ -74,77 +71,5 @@ private boolean isMatched(S item) {
7471
return false;
7572
}
7673
}
77-
78-
/**
79-
* <p>
80-
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over
81-
* the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere
82-
* in the specified matchers. For a positive match, the examined iterable must be of the same
83-
* length as the number of specified matchers.
84-
* </p>
85-
* <p>
86-
* N.B. each of the specified matchers will only be used once during a given examination, so be
87-
* careful when specifying matchers that may be satisfied by more than one entry in an examined
88-
* iterable.
89-
* </p>
90-
* <p>
91-
* For example:
92-
* </p>
93-
* <pre>assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(equalTo("bar"), equalTo("foo")))</pre>
94-
*
95-
* @param itemMatchers
96-
* a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable}
97-
*/
98-
@SafeVarargs
99-
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Matcher<? super T>... itemMatchers) {
100-
return containsInAnyOrder(asList(itemMatchers));
101-
}
102-
103-
/**
104-
* <p>
105-
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over
106-
* the examined {@link Iterable} yields a series of items, each logically equal to one item
107-
* anywhere in the specified items. For a positive match, the examined iterable
108-
* must be of the same length as the number of specified items.
109-
* </p>
110-
* <p>
111-
* N.B. each of the specified items will only be used once during a given examination, so be
112-
* careful when specifying items that may be equal to more than one entry in an examined
113-
* iterable.
114-
* </p>
115-
* <p>
116-
* For example:
117-
* </p>
118-
* <pre>assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))</pre>
119-
*
120-
* @param items
121-
* the items that must equal the items provided by an examined {@link Iterable} in any order
122-
*/
123-
@SafeVarargs
124-
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(T... items) {
125-
return new IsIterableContainingInAnyOrder<>(Wrapping.asEqualToMatchers(items));
126-
}
127-
128-
/**
129-
* <p>
130-
* Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over
131-
* the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere
132-
* in the specified collection of matchers. For a positive match, the examined iterable
133-
* must be of the same length as the specified collection of matchers.
134-
* </p>
135-
* <p>
136-
* N.B. each matcher in the specified collection will only be used once during a given
137-
* examination, so be careful when specifying matchers that may be satisfied by more than
138-
* one entry in an examined iterable.
139-
* </p>
140-
* <p>For example:</p>
141-
* <pre>assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))</pre>
142-
*
143-
* @param itemMatchers
144-
* a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable}
145-
*/
146-
public static <T> Matcher<Iterable<? extends T>> containsInAnyOrder(Collection<Matcher<? super T>> itemMatchers) {
147-
return new IsIterableContainingInAnyOrder<>(itemMatchers);
148-
}
14974
}
15075

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.util.Collections;
88

99
import static java.util.Arrays.asList;
10-
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
1110
import static org.hamcrest.collection.IsIterableContainingInOrderTest.make;
1211
import static org.hamcrest.collection.IsIterableContainingInOrderTest.value;
12+
import static org.hamcrest.collection.MatchIterables.containsInAnyOrder;
1313

1414
public class IsIterableContainingInAnyOrderTest extends AbstractMatcherTest {
1515

0 commit comments

Comments
 (0)