JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Create Iterable/Collection matcher like: doesNotContainAnyOf(T [] items)

Open Vitalik549 opened this issue 7 years ago • 1 comments

Case:

List<String> list = Arrays.asList("a", "b", "c");
String[] cd = {"c", "d"};

assertThat("Should not contain each item", list, not(hasItems(cd)));

This assertion won't fail. I understand why it will pass, though it's not expected by most of users.

It would be nice to have simple Matcher to check that "every item is not in the list"

# Now it's possible to use:
assertThat("Should not contain each item", list, everyItem(not(isIn(cd))));

# But that looks much better:
assertThat("Should not contain each item", list,  doesNotContainAnyOf(cd));

Vitalik549 avatar Mar 12 '18 14:03 Vitalik549

Hello. I implemented a method to check whether two Iterables intersect and submitted a PR.

XxxXxxXxx233 avatar Apr 25 '21 11:04 XxxXxxXxx233