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
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
Negate the hasItem
assertion
assertThat(someCollection, not(hasItem(someItem)))
Matcherzs
defines all of the. factory methods so you can have a single *
static import. I'll look it up a work if no one else posts the line in the next hour. –
Rhebarhee import static org.hamcrest.MatcherAssert.assertThat;
and import static org.hamcrest.Matchers.*;
–
Rhebarhee 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();
or you can do;
.extract().jsonPath().getObject("data", pojo.class);
(above is response)
assertThat(response, not(hasItem(bodyYouArePosting)));
© 2022 - 2024 — McMap. All rights reserved.
import static org.hamcrest.core.IsNot.not
) it worked well. – Kalikalian