Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assert collection does not contain item

Tags:

java

hamcrest

Using the hamcrest library for Java, what's a nicely readable way to do the opposite of:

assertThat(someCollection, hasItem(someItem)) 

I want to make sure someCollection does not contain item someItem

like image 206
harschware Avatar asked Feb 20 '12 02:02

harschware


People also ask

Does not contain assertion?

The Not Contains assertion verifies that some specific value is missing from the message.

Is not Hamcrest?

Class IsNot<T> Calculates the logical negation of a matcher. Generates a description of the object. Evaluates the matcher for argument item .


1 Answers

Negate the hasItem assertion

assertThat(someCollection, not(hasItem(someItem))) 
like image 168
dee-see Avatar answered Sep 23 '22 19:09

dee-see