hasItems(notExpected...)
would only match current
if all elements from notExpected
were also in current
. So with the line
assertThat(current, not(hasItems(notExpected...)));
you assert that current
doesn't contain all elements from notExpected
.
One solution to assert that current
doesn't contain any elements from notExpected
:
assertThat(current, everyItem(not(isIn(notExpected))));
and then you don't even have to convert the list to array. This variant maybe a bit more readable, but requires conversion to array:
assertThat(current, everyItem(not(isOneOf(notExpected...))));
Note that these matchers are not from CoreMatchers
in hamcrest-core
, so you will need to add a dependency on hamcrest-library
.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>