assert collection does not contain item assert collection does not contain item java java

assert collection does not contain item


Negate the hasItem assertion

assertThat(someCollection, not(hasItem(someItem)))


If you need to Assert an Array, the same logic use not(hasItemInArray())

final String[] availableIds = {"123", "321"};final String userId = "333";softAssert.assertThat("Id not found", availableIds, not(hasItemInArray(userId)));softAssert.assertAll();