File tree Expand file tree Collapse file tree
hamcrest-library/src/main/java/org/hamcrest/collection Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import org .hamcrest .Matcher ;
77import org .hamcrest .TypeSafeMatcher ;
88
9+ /**
10+ * Matcher for array whose elements satisfy a sequence of matchers.
11+ * The array size must equal the number of element matchers.
12+ */
913public class IsArray <T > extends TypeSafeMatcher <T []> {
1014 private final Matcher <T >[] elementMatchers ;
1115
@@ -58,6 +62,9 @@ protected String descriptionEnd() {
5862 return "]" ;
5963 }
6064
65+ /**
66+ * Evaluates to true only if each matcher[i] is satisfied by array[i].
67+ */
6168 public static <T > IsArray <T > array (Matcher <T >... elementMatchers ) {
6269 return new IsArray <T >(elementMatchers );
6370 }
Original file line number Diff line number Diff line change 66import org .hamcrest .TypeSafeMatcher ;
77import static org .hamcrest .core .IsEqual .equalTo ;
88
9+ /**
10+ * Matches if an array contains an item satisfying a nested matcher.
11+ */
912public class IsArrayContaining <T > extends TypeSafeMatcher <T []> {
10-
1113 private final Matcher <T > elementMatcher ;
1214
1315 public IsArrayContaining (Matcher <T > elementMatcher ) {
@@ -29,14 +31,22 @@ public void describeTo(Description description) {
2931 .appendDescriptionOf (elementMatcher );
3032 }
3133
34+ /**
35+ * Evaluates to true if any item in an array satisfies the given matcher.
36+ */
3237 @ Factory
3338 public static <T > Matcher <T []> hasItemInArray (Matcher <T > elementMatcher ) {
3439 return new IsArrayContaining <T >(elementMatcher );
3540 }
3641
42+ /**
43+ * This is a shortcut to the frequently used hasItemInArray(equalTo(x)).
44+ *
45+ * For example, assertThat(hasItemInArray(equal_to(x)))
46+ * vs. assertThat(hasItemInArray(x))
47+ */
3748 @ Factory
3849 public static <T > Matcher <T []> hasItemInArray (T element ) {
3950 return hasItemInArray (equalTo (element ));
4051 }
41-
4252}
You can’t perform that action at this time.
0 commit comments