Skip to content

Commit d7b28fc

Browse files
committed
Started extracting Matching grouping classes
1 parent f540af9 commit d7b28fc

File tree

7 files changed

+92
-14
lines changed

7 files changed

+92
-14
lines changed

BUILDING.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
--[ Build requirements ]-------------------------------------
66

7-
* JDK 1.7
7+
* JDK 1.8
88

99
* Gradle
1010

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ They've also been used for other purposes.
1313

1414
Downloads
1515
---------
16-
You can obtain Hamcrest binaries from [maven central][], or from [google code downloads][].
16+
You can obtain Hamcrest binaries from [maven central][]
1717

1818
Extensions
1919
----------

hamcrest-core/src/main/java/org/hamcrest/CoreMatchers.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String d
153153
*
154154
* @param itemMatcher
155155
* the matcher to apply to items provided by the examined {@link Iterable}
156+
* @Deprecated use org.hamcrest.MatchingCollections instead
156157
*/
157158
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) {
158-
return org.hamcrest.core.IsCollectionContaining.hasItem(itemMatcher);
159+
return MatchingCollections.hasItem(itemMatcher);
159160
}
160161

161162
/**
@@ -168,9 +169,10 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(or
168169
*
169170
* @param item
170171
* the item to compare against the items provided by the examined {@link Iterable}
172+
* @Deprecated use org.hamcrest.MatchingCollections instead
171173
*/
172174
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) {
173-
return org.hamcrest.core.IsCollectionContaining.hasItem(item);
175+
return MatchingCollections.hasItem(item);
174176
}
175177

176178
/**
@@ -183,10 +185,11 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T
183185
*
184186
* @param itemMatchers
185187
* the matchers to apply to items provided by the examined {@link Iterable}
188+
* @Deprecated use org.hamcrest.MatchingCollections instead
186189
*/
187190
@SafeVarargs
188191
public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) {
189-
return org.hamcrest.core.IsCollectionContaining.hasItems(itemMatchers);
192+
return MatchingCollections.hasItems(itemMatchers);
190193
}
191194

192195
/**
@@ -199,10 +202,11 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcr
199202
*
200203
* @param items
201204
* the items to compare against the items provided by the examined {@link Iterable}
205+
* @Deprecated use org.hamcrest.MatchingCollections instead
202206
*/
203207
@SafeVarargs
204208
public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) {
205-
return org.hamcrest.core.IsCollectionContaining.hasItems(items);
209+
return MatchingCollections.hasItems(items);
206210
}
207211

208212
/**

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

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

3+
import org.hamcrest.collection.IsCollectionContaining;
4+
35
public class Matchers {
46

57
/**
@@ -241,7 +243,7 @@ public static org.hamcrest.Matcher<java.lang.Object> anything(java.lang.String d
241243
* the matcher to apply to items provided by the examined {@link Iterable}
242244
*/
243245
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) {
244-
return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher);
246+
return IsCollectionContaining.<T>hasItem(itemMatcher);
245247
}
246248

247249
/**
@@ -256,7 +258,7 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(or
256258
* the item to compare against the items provided by the examined {@link Iterable}
257259
*/
258260
public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) {
259-
return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item);
261+
return IsCollectionContaining.<T>hasItem(item);
260262
}
261263

262264
/**
@@ -271,7 +273,7 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T
271273
* the matchers to apply to items provided by the examined {@link Iterable}
272274
*/
273275
public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcrest.Matcher<? super T>... itemMatchers) {
274-
return org.hamcrest.core.IsCollectionContaining.<T>hasItems(itemMatchers);
276+
return IsCollectionContaining.<T>hasItems(itemMatchers);
275277
}
276278

277279
/**
@@ -286,7 +288,7 @@ public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(org.hamcr
286288
* the items to compare against the items provided by the examined {@link Iterable}
287289
*/
288290
public static <T> org.hamcrest.Matcher<java.lang.Iterable<T>> hasItems(T... items) {
289-
return org.hamcrest.core.IsCollectionContaining.<T>hasItems(items);
291+
return IsCollectionContaining.<T>hasItems(items);
290292
}
291293

292294
/**
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.hamcrest;
2+
3+
import org.hamcrest.collection.IsCollectionContaining;
4+
5+
/**
6+
* @author 2015 http://www.hamcrest.com
7+
*/
8+
public class MatchingCollections {
9+
/**
10+
* Creates a matcher for {@link Iterable}s that only matches when a single pass over the
11+
* examined {@link Iterable} yields at least one item that is matched by the specified
12+
* <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable}
13+
* will stop as soon as a matching item is found.
14+
* For example:
15+
* <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre>
16+
*
17+
* @param itemMatcher
18+
* the matcher to apply to items provided by the examined {@link Iterable}
19+
*/
20+
public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher) {
21+
return IsCollectionContaining.hasItem(itemMatcher);
22+
}
23+
24+
/**
25+
* Creates a matcher for {@link Iterable}s that only matches when a single pass over the
26+
* examined {@link Iterable} yields at least one item that is equal to the specified
27+
* <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable}
28+
* will stop as soon as a matching item is found.
29+
* For example:
30+
* <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre>
31+
*
32+
* @param item
33+
* the item to compare against the items provided by the examined {@link Iterable}
34+
*/
35+
public static <T> Matcher<Iterable<? super T>> hasItem(T item) {
36+
return IsCollectionContaining.hasItem(item);
37+
}
38+
39+
/**
40+
* Creates a matcher for {@link Iterable}s that matches when consecutive passes over the
41+
* examined {@link Iterable} yield at least one item that is matched by the corresponding
42+
* matcher from the specified <code>itemMatchers</code>. Whilst matching, each traversal of
43+
* the examined {@link Iterable} will stop as soon as a matching item is found.
44+
* For example:
45+
* <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))</pre>
46+
*
47+
* @param itemMatchers
48+
* the matchers to apply to items provided by the examined {@link Iterable}
49+
*/
50+
@SafeVarargs
51+
public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) {
52+
return IsCollectionContaining.hasItems(itemMatchers);
53+
}
54+
55+
/**
56+
* Creates a matcher for {@link Iterable}s that matches when consecutive passes over the
57+
* examined {@link Iterable} yield at least one item that is equal to the corresponding
58+
* item from the specified <code>items</code>. Whilst matching, each traversal of the
59+
* examined {@link Iterable} will stop as soon as a matching item is found.
60+
* For example:
61+
* <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre>
62+
*
63+
* @param items
64+
* the items to compare against the items provided by the examined {@link Iterable}
65+
*/
66+
@SafeVarargs
67+
public static <T> Matcher<Iterable<T>> hasItems(T... items) {
68+
return IsCollectionContaining.hasItems(items);
69+
}
70+
}

hamcrest-core/src/main/java/org/hamcrest/core/IsCollectionContaining.java renamed to hamcrest-library/src/main/java/org/hamcrest/collection/IsCollectionContaining.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.hamcrest.core;
1+
package org.hamcrest.collection;
22

33
import org.hamcrest.Description;
44
import org.hamcrest.Matcher;

hamcrest-core/src/test/java/org/hamcrest/core/IsCollectionContainingTest.java renamed to hamcrest-library/src/test/java/org/hamcrest/collection/IsCollectionContainingTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package org.hamcrest.core;
1+
package org.hamcrest.collection;
22

33
import org.hamcrest.Description;
44
import org.hamcrest.Matcher;
55
import org.hamcrest.TypeSafeDiagnosingMatcher;
6+
import org.hamcrest.collection.IsCollectionContaining;
7+
import org.hamcrest.core.IsEqual;
68
import org.junit.Test;
79

810
import java.util.ArrayList;
@@ -11,8 +13,8 @@
1113

1214
import static java.util.Arrays.asList;
1315
import static org.hamcrest.AbstractMatcherTest.*;
14-
import static org.hamcrest.core.IsCollectionContaining.hasItem;
15-
import static org.hamcrest.core.IsCollectionContaining.hasItems;
16+
import static org.hamcrest.collection.IsCollectionContaining.hasItem;
17+
import static org.hamcrest.collection.IsCollectionContaining.hasItems;
1618
import static org.hamcrest.core.IsEqual.equalTo;
1719

1820
public final class IsCollectionContainingTest {

0 commit comments

Comments
 (0)