Skip to content

Commit 67c72cf

Browse files
committed
Collapsing factory methods hasItemInArray
1 parent e4cf3c4 commit 67c72cf

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public static <T> org.hamcrest.collection.IsArray<T> array(org.hamcrest.Matcher<
499499
* @param elementMatcher the matcher to apply to elements in examined arrays
500500
*/
501501
public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<? super T> elementMatcher) {
502-
return org.hamcrest.collection.IsArrayContaining.hasItemInArray(elementMatcher);
502+
return MatchArrays.hasItemInArray(elementMatcher);
503503
}
504504

505505
/**
@@ -512,7 +512,7 @@ public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(org.hamcrest.Matcher<
512512
* @param element the element that should be present in examined arrays
513513
*/
514514
public static <T> org.hamcrest.Matcher<T[]> hasItemInArray(T element) {
515-
return org.hamcrest.collection.IsArrayContaining.hasItemInArray(element);
515+
return MatchArrays.hasItemInArray(element);
516516
}
517517

518518
/**

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import java.util.Arrays;
88

9-
import static org.hamcrest.core.IsEqual.equalTo;
10-
119
/**
1210
* Matches if an array contains an item satisfying a nested matcher.
1311
*/
@@ -40,32 +38,4 @@ public void describeTo(Description description) {
4038
.appendDescriptionOf(elementMatcher);
4139
}
4240

43-
/**
44-
* Creates a matcher for arrays that matches when the examined array contains at least one item
45-
* that is matched by the specified <code>elementMatcher</code>. Whilst matching, the traversal
46-
* of the examined array will stop as soon as a matching element is found.
47-
* For example:
48-
* <pre>assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))</pre>
49-
*
50-
* @param elementMatcher
51-
* the matcher to apply to elements in examined arrays
52-
*/
53-
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher) {
54-
return new IsArrayContaining<>(elementMatcher);
55-
}
56-
57-
/**
58-
* A shortcut to the frequently used <code>hasItemInArray(equalTo(x))</code>.
59-
* For example:
60-
* <pre>assertThat(hasItemInArray(x))</pre>
61-
* instead of:
62-
* <pre>assertThat(hasItemInArray(equalTo(x)))</pre>
63-
*
64-
* @param element
65-
* the element that should be present in examined arrays
66-
*/
67-
public static <T> Matcher<T[]> hasItemInArray(T element) {
68-
Matcher<? super T> matcher = equalTo(element);
69-
return IsArrayContaining.hasItemInArray(matcher);
70-
}
7141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static <T> IsArray<T> array(Matcher<? super T>... elementMatchers) {
3636
* @param elementMatcher the matcher to apply to elements in examined arrays
3737
*/
3838
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher) {
39-
return IsArrayContaining.hasItemInArray(elementMatcher);
39+
return new IsArrayContaining<>(elementMatcher);
4040
}
4141

4242
/**
@@ -49,7 +49,7 @@ public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher)
4949
* @param element the element that should be present in examined arrays
5050
*/
5151
public static <T> Matcher<T[]> hasItemInArray(T element) {
52-
return IsArrayContaining.hasItemInArray(element);
52+
return hasItemInArray(equalTo(element));
5353
}
5454

5555
/**

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

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

6-
import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
6+
import static org.hamcrest.collection.MatchArrays.hasItemInArray;
7+
78

89
public class IsArrayContainingTest extends AbstractMatcherTest {
910

0 commit comments

Comments
 (0)