Try this method:
public <T> Matcher<Iterable<? super T>> doesNotContainAnyOf(T... elements) { Matcher<Iterable<? super T>> matcher = null; for(T e : elements) { matcher = matcher == null ? Matchers.not(Matchers.hasItem(e)) : Matchers.allOf(matcher, Matchers.not(Matchers.hasItem(e))); } return matcher; }
In this case:
List<String> list = Arrays.asList("a", "b", "c"); // True MatcherAssert.assertThat(list, doesNotContainAnyOf("z","e", "f", "d")); // False MatcherAssert.assertThat(list, doesNotContainAnyOf("a","e", "f", "d"));
source share