Skip to content

Commit b99812c

Browse files
committed
Collapsing factory methods. Arrays
1 parent debe783 commit b99812c

4 files changed

Lines changed: 35 additions & 40 deletions

File tree

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

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

3+
import org.hamcrest.collection.MatchArrays;
34
import org.hamcrest.number.MatchNumbers;
45
import org.hamcrest.object.MatchObjects;
56
import org.hamcrest.text.MatchStrings;
@@ -645,7 +646,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(org.hamcrest.Matcher<?
645646
* @param size the length that an examined array must have for a positive match
646647
*/
647648
public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(int size) {
648-
return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(size);
649+
return MatchArrays.arrayWithSize(size);
649650
}
650651

651652
/**
@@ -655,7 +656,7 @@ public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(int size) {
655656
* <pre>assertThat(new String[0], emptyArray())</pre>
656657
*/
657658
public static <E> org.hamcrest.Matcher<E[]> emptyArray() {
658-
return org.hamcrest.collection.IsArrayWithSize.emptyArray();
659+
return MatchArrays.emptyArray();
659660
}
660661

661662
/**

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayWithSize.java‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.hamcrest.FeatureMatcher;
44
import org.hamcrest.Matcher;
55

6-
import static org.hamcrest.core.DescribedAs.describedAs;
76
import static org.hamcrest.core.IsEqual.equalTo;
87

98
/**
@@ -45,15 +44,4 @@ public static <E> Matcher<E[]> arrayWithSize(int size) {
4544
return arrayWithSize(equalTo(size));
4645
}
4746

48-
/**
49-
* Creates a matcher for arrays that matches when the <code>length</code> of the array
50-
* is zero.
51-
* For example:
52-
* <pre>assertThat(new String[0], emptyArray())</pre>
53-
*
54-
*/
55-
public static <E> Matcher<E[]> emptyArray() {
56-
Matcher<E[]> isEmpty = arrayWithSize(0);
57-
return describedAs("an empty array", isEmpty);
58-
}
5947
}

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.hamcrest.collection;
22

3+
import org.hamcrest.Matcher;
4+
5+
import java.util.Collection;
6+
7+
import static org.hamcrest.core.DescribedAs.describedAs;
8+
39
public class MatchArrays {
410
/**
511
* Creates a matcher that matches arrays whose elements are satisfied by the specified matchers. Matches
@@ -11,8 +17,8 @@ public class MatchArrays {
1117
* @param elementMatchers the matchers that the elements of examined arrays should satisfy
1218
*/
1319
@SafeVarargs
14-
public static <T> org.hamcrest.collection.IsArray<T> array(org.hamcrest.Matcher<? super T>... elementMatchers) {
15-
return org.hamcrest.collection.IsArray.array(elementMatchers);
20+
public static <T> IsArray<T> array(Matcher<? super T>... elementMatchers) {
21+
return IsArray.array(elementMatchers);
1622
}
1723

1824
/**
@@ -24,8 +30,8 @@ public static <T> org.hamcrest.collection.IsArray<T> array(org.hamcrest.Matcher<
2430
*
2531
* @param elementMatcher the matcher to apply to elements in examined arrays
2632
*/
27-
public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<? super T> elementMatcher) {
28-
return org.hamcrest.collection.IsArrayContaining.hasItemInArray(elementMatcher);
33+
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher) {
34+
return IsArrayContaining.hasItemInArray(elementMatcher);
2935
}
3036

3137
/**
@@ -37,8 +43,8 @@ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<
3743
*
3844
* @param element the element that should be present in examined arrays
3945
*/
40-
public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element) {
41-
return org.hamcrest.collection.IsArrayContaining.hasItemInArray(element);
46+
public static <T> Matcher<T[]> hasItemInArray(T element) {
47+
return IsArrayContaining.hasItemInArray(element);
4248
}
4349

4450
/**
@@ -51,8 +57,8 @@ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element) {
5157
* @param items the items that must equal the items within an examined array
5258
*/
5359
@SafeVarargs
54-
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items) {
55-
return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(items);
60+
public static <E> Matcher<E[]> arrayContaining(E... items) {
61+
return IsArrayContainingInOrder.arrayContaining(items);
5662
}
5763

5864
/**
@@ -65,8 +71,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(E... items) {
6571
* @param itemMatchers the matchers that must be satisfied by the items in the examined array
6672
*/
6773
@SafeVarargs
68-
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher<? super E>... itemMatchers) {
69-
return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(itemMatchers);
74+
public static <E> Matcher<E[]> arrayContaining(Matcher<? super E>... itemMatchers) {
75+
return IsArrayContainingInOrder.arrayContaining(itemMatchers);
7076
}
7177

7278
/**
@@ -78,8 +84,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(org.hamcrest.Matcher
7884
*
7985
* @param itemMatchers a list of matchers, each of which must be satisfied by the corresponding item in an examined array
8086
*/
81-
public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.hamcrest.Matcher<? super E>> itemMatchers) {
82-
return org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining(itemMatchers);
87+
public static <E> Matcher<E[]> arrayContaining(java.util.List<Matcher<? super E>> itemMatchers) {
88+
return IsArrayContainingInOrder.arrayContaining(itemMatchers);
8389
}
8490

8591
/**
@@ -102,8 +108,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContaining(java.util.List<org.h
102108
* @param itemMatchers a list of matchers, each of which must be satisfied by an entry in an examined array
103109
*/
104110
@SafeVarargs
105-
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcrest.Matcher<? super E>... itemMatchers) {
106-
return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
111+
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Matcher<? super E>... itemMatchers) {
112+
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
107113
}
108114

109115
/**
@@ -125,8 +131,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(org.hamcre
125131
*
126132
* @param itemMatchers a list of matchers, each of which must be satisfied by an item provided by an examined array
127133
*/
128-
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.Collection<org.hamcrest.Matcher<? super E>> itemMatchers) {
129-
return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
134+
public static <E> Matcher<E[]> arrayContainingInAnyOrder(Collection<Matcher<? super E>> itemMatchers) {
135+
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(itemMatchers);
130136
}
131137

132138
/**
@@ -147,8 +153,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(java.util.
147153
* @param items the items that must equal the entries of an examined array, in any order
148154
*/
149155
@SafeVarargs
150-
public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(E... items) {
151-
return org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(items);
156+
public static <E> Matcher<E[]> arrayContainingInAnyOrder(E... items) {
157+
return IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(items);
152158
}
153159

154160
/**
@@ -159,8 +165,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayContainingInAnyOrder(E... items
159165
*
160166
* @param sizeMatcher a matcher for the length of an examined array
161167
*/
162-
public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(org.hamcrest.Matcher<? super java.lang.Integer> sizeMatcher) {
163-
return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(sizeMatcher);
168+
public static <E> Matcher<E[]> arrayWithSize(Matcher<? super Integer> sizeMatcher) {
169+
return IsArrayWithSize.arrayWithSize(sizeMatcher);
164170
}
165171

166172
/**
@@ -171,8 +177,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(org.hamcrest.Matcher<?
171177
*
172178
* @param size the length that an examined array must have for a positive match
173179
*/
174-
public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(int size) {
175-
return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(size);
180+
public static <E> Matcher<E[]> arrayWithSize(int size) {
181+
return IsArrayWithSize.arrayWithSize(size);
176182
}
177183

178184
/**
@@ -181,8 +187,8 @@ public static <E> org.hamcrest.Matcher<E[]> arrayWithSize(int size) {
181187
* For example:
182188
* <pre>assertThat(new String[0], emptyArray())</pre>
183189
*/
184-
public static <E> org.hamcrest.Matcher<E[]> emptyArray() {
185-
return org.hamcrest.collection.IsArrayWithSize.emptyArray();
190+
public static <E> Matcher<E[]> emptyArray() {
191+
return describedAs("an empty array", IsArrayWithSize.<E>arrayWithSize(0));
186192
}
187193

188194
}

‎hamcrest-library/src/test/java/org/hamcrest/collection/IsArrayWithSizeTest.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.IsArrayWithSize.arrayWithSize;
7-
import static org.hamcrest.collection.IsArrayWithSize.emptyArray;
6+
import static org.hamcrest.collection.MatchArrays.arrayWithSize;
7+
import static org.hamcrest.collection.MatchArrays.emptyArray;
88
import static org.hamcrest.core.IsEqual.equalTo;
99

1010
public class IsArrayWithSizeTest extends AbstractMatcherTest {

0 commit comments

Comments
 (0)