Skip to content

Commit e4cf3c4

Browse files
committed
Collapsing factory methods arrayContainsInAnyOrder
1 parent a7fa9d8 commit e4cf3c4

File tree

3 files changed

+5
-85
lines changed

3 files changed

+5
-85
lines changed

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

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
import org.hamcrest.Matcher;
55
import org.hamcrest.TypeSafeMatcher;
66

7-
import java.util.ArrayList;
87
import java.util.Arrays;
98
import java.util.Collection;
10-
import java.util.List;
11-
12-
import static org.hamcrest.core.IsEqual.equalTo;
139

1410
public class IsArrayContainingInAnyOrder<E> extends TypeSafeMatcher<E[]> {
1511
private final IsIterableContainingInAnyOrder<E> iterableMatcher;
@@ -35,80 +31,4 @@ public void describeTo(Description description) {
3531
description.appendList("[", ", ", "]", matchers)
3632
.appendText(" in any order");
3733
}
38-
39-
/**
40-
* <p>
41-
* Creates an order agnostic matcher for arrays that matches when each item in the
42-
* examined array satisfies one matcher anywhere in the specified matchers.
43-
* For a positive match, the examined array must be of the same length as the number of
44-
* specified matchers.
45-
* </p>
46-
* <p>
47-
* N.B. each of the specified matchers will only be used once during a given examination, so be
48-
* careful when specifying matchers that may be satisfied by more than one entry in an examined
49-
* array.
50-
* </p>
51-
* <p>
52-
* For example:
53-
* </p>
54-
* <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))</pre>
55-
*
56-
* @param itemMatchers
57-
* a list of matchers, each of which must be satisfied by an entry in an examined array
58-
*/
59-
@SafeVarargs
60-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) {
61-
return arrayContainingInAnyOrder(Arrays.asList(itemMatchers));
62-
}
63-
64-
/**
65-
* <p>
66-
* Creates an order agnostic matcher for arrays that matches when each item in the
67-
* examined array satisfies one matcher anywhere in the specified collection of matchers.
68-
* For a positive match, the examined array must be of the same length as the specified collection
69-
* of matchers.
70-
* </p>
71-
* <p>
72-
* N.B. each matcher in the specified collection will only be used once during a given
73-
* examination, so be careful when specifying matchers that may be satisfied by more than
74-
* one entry in an examined array.
75-
* </p>
76-
* <p>
77-
* For example:
78-
* </p>
79-
* <pre>assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))</pre>
80-
*
81-
* @param itemMatchers
82-
* a list of matchers, each of which must be satisfied by an item provided by an examined array
83-
*/
84-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> itemMatchers) {
85-
return new IsArrayContainingInAnyOrder<>(itemMatchers);
86-
}
87-
88-
/**
89-
* <p>Creates an order agnostic matcher for arrays that matches when each item in the
90-
* examined array is logically equal to one item anywhere in the specified items.
91-
* For a positive match, the examined array must be of the same length as the number of
92-
* specified items.
93-
* </p>
94-
* <p>N.B. each of the specified items will only be used once during a given examination, so be
95-
* careful when specifying items that may be equal to more than one entry in an examined
96-
* array.
97-
* </p>
98-
* <p>
99-
* For example:
100-
* </p>
101-
* <pre>assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))</pre>
102-
*
103-
* @param items
104-
* the items that must equal the entries of an examined array, in any order
105-
*/
106-
@SafeVarargs
107-
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
108-
List<Matcher<? super E>> matchers = new ArrayList<>();
109-
for (E item : items) {
110-
matchers.add(equalTo(item));
111-
}
112-
return new IsArrayContainingInAnyOrder<>(matchers);
113-
}
11434
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static <E> Matcher<E[]> arrayContaining(List<Matcher<? super E>> itemMatc
114114
*/
115115
@SafeVarargs
116116
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) {
117-
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
117+
return arrayContainingInAnyOrder(Wrapping.nullSafe(itemMatchers));
118118
}
119119

120120
/**
@@ -137,7 +137,7 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... i
137137
* @param itemMatchers a list of matchers, each of which must be satisfied by an item provided by an examined array
138138
*/
139139
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> itemMatchers) {
140-
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
140+
return new IsArrayContainingInAnyOrder<>(itemMatchers);
141141
}
142142

143143
/**
@@ -159,7 +159,7 @@ public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? su
159159
*/
160160
@SafeVarargs
161161
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
162-
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(items);
162+
return arrayContainingInAnyOrder(Wrapping.asEqualToMatchers(items));
163163
}
164164

165165
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.hamcrest.AbstractMatcherTest;
44
import org.hamcrest.Matcher;
55

6-
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
7-
import static org.hamcrest.core.IsEqual.equalTo;
6+
import static org.hamcrest.collection.MatchArrays.arrayContainingInAnyOrder;
7+
import static org.hamcrest.object.MatchObjects.equalTo;
88

99
public class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest {
1010

0 commit comments

Comments
 (0)