/**
* Creates a matcher that matches if the examined lambda does no accept {@code null}
* in its input values. The examined lambda takes an array as only argument and is
* expected to throw a {@link NullPointerException} if this array is {@code null} and
* an {@link IllegalArgumentException} if the array contains {@code null}.
*
* @param <CONSUMED_TYPE> type of the elements of the array the examined lambda takes
* as its argument.
* @param testValues An array of valid values that can be passed to the examined
* lambda without it throwing an exception.
* @return A matcher, as described above.
*/
public static <CONSUMED_TYPE> Matcher<Consumer<CONSUMED_TYPE[]>> notAcceptingNull(
final CONSUMED_TYPE[] testValues) {
final NotAcceptingNullInListMatcher<CONSUMED_TYPE> listMatcher =
THIZ.new NotAcceptingNullInListMatcher<>(Arrays.asList(testValues));
// hack to get an empty array of CONSUMED_TYPE without SurpressWarnings
final CONSUMED_TYPE[] copyInstance = ArrayUtils.clone(testValues);
ArrayUtils.removeElements(copyInstance, copyInstance);
return new TypeSafeDiagnosingMatcher<Consumer<CONSUMED_TYPE[]>>() {
@Override
public void describeTo(final Description description) {
listMatcher.describeTo(description);
}
@Override
protected boolean matchesSafely(final Consumer<CONSUMED_TYPE[]> item,
final Description mismatchDescription) {
return listMatcher.matchesSafely((list) -> item.accept(list.toArray(copyInstance)),
mismatchDescription);
}
};
}
NullHandlingMatchers.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:Beagle
作者:
评论列表
文章目录