Skip to content

Commit 69f4ab3

Browse files
author
jon.m.reid
committed
Adding comments
1 parent 10a76e4 commit 69f4ab3

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import org.hamcrest.Matcher;
77
import 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+
*/
913
public 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
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import org.hamcrest.TypeSafeMatcher;
77
import static org.hamcrest.core.IsEqual.equalTo;
88

9+
/**
10+
* Matches if an array contains an item satisfying a nested matcher.
11+
*/
912
public 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
}

0 commit comments

Comments
 (0)