Skip to content

Commit f956559

Browse files
committed
factory methods for empty collections
1 parent 7c629d3 commit f956559

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

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

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

33
import org.hamcrest.collection.MatchArrays;
4+
import org.hamcrest.collection.MatchCollections;
45
import org.hamcrest.collection.MatchIterables;
56
import org.hamcrest.number.MatchNumbers;
67
import org.hamcrest.object.MatchObjects;
@@ -725,7 +726,7 @@ public static <E> org.hamcrest.Matcher<java.util.Collection<? extends E>> hasSiz
725726
* <pre>assertThat(new ArrayList&lt;String&gt;(), is(empty()))</pre>
726727
*/
727728
public static <E> org.hamcrest.Matcher<java.util.Collection<? extends E>> empty() {
728-
return org.hamcrest.collection.IsEmptyCollection.empty();
729+
return MatchCollections.empty();
729730
}
730731

731732
/**
@@ -737,7 +738,7 @@ public static <E> org.hamcrest.Matcher<java.util.Collection<? extends E>> empty(
737738
* @param unusedToForceReturnType the type of the collection's content
738739
*/
739740
public static <E> org.hamcrest.Matcher<java.util.Collection<E>> emptyCollectionOf(java.lang.Class<E> unusedToForceReturnType) {
740-
return org.hamcrest.collection.IsEmptyCollection.emptyCollectionOf(unusedToForceReturnType);
741+
return MatchCollections.emptyCollectionOf(unusedToForceReturnType);
741742
}
742743

743744
/**
Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hamcrest.collection;
22

33
import org.hamcrest.Description;
4-
import org.hamcrest.Matcher;
54
import org.hamcrest.TypeSafeMatcher;
65

76
import java.util.Collection;
@@ -26,28 +25,4 @@ public void describeTo(Description description) {
2625
description.appendText("an empty collection");
2726
}
2827

29-
/**
30-
* Creates a matcher for {@link java.util.Collection}s matching examined collections whose <code>isEmpty</code>
31-
* method returns <code>true</code>.
32-
* For example:
33-
* <pre>assertThat(new ArrayList&lt;String&gt;(), is(empty()))</pre>
34-
*
35-
*/
36-
public static <E> Matcher<Collection<? extends E>> empty() {
37-
return new IsEmptyCollection<>();
38-
}
39-
40-
/**
41-
* Creates a matcher for {@link java.util.Collection}s matching examined collections whose <code>isEmpty</code>
42-
* method returns <code>true</code>.
43-
* For example:
44-
* <pre>assertThat(new ArrayList&lt;String&gt;(), is(emptyCollectionOf(String.class)))</pre>
45-
*
46-
* @param unusedToForceReturnType
47-
* the type of the collection's content
48-
*/
49-
@SuppressWarnings({"unchecked", "UnusedParameters"})
50-
public static <E> Matcher<Collection<E>> emptyCollectionOf(Class<E> unusedToForceReturnType) {
51-
return (Matcher)empty();
52-
}
5328
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public static <E> Matcher<Collection<? extends E>> empty() {
5252
*
5353
* @param unusedToForceReturnType the type of the collection's content
5454
*/
55-
public static <E> Matcher<Collection<? extends E>> emptyCollectionOf(Class<E> unusedToForceReturnType) {
56-
return new IsEmptyCollection<>();
55+
@SuppressWarnings("unchecked")
56+
public static <E> Matcher<Collection<E>> emptyCollectionOf(Class<E> unusedToForceReturnType) {
57+
return (Matcher)empty();
5758
}
5859
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.Collection;
88

99
import static java.util.Arrays.asList;
10-
import static org.hamcrest.collection.IsEmptyCollection.empty;
10+
import static org.hamcrest.collection.MatchCollections.empty;
1111
import static org.hamcrest.core.Is.is;
1212

1313
public class IsEmptyCollectionTest extends AbstractMatcherTest {
@@ -30,7 +30,7 @@ public void testHasAReadableDescription() {
3030
}
3131

3232
public void testCompiles() {
33-
needs(IsEmptyCollection.emptyCollectionOf(String.class));
33+
needs(MatchCollections.emptyCollectionOf(String.class));
3434
}
3535

3636
private void needs(@SuppressWarnings("unused") Matcher<Collection<String>> bar) { }

0 commit comments

Comments
 (0)