not(hasItems()) does not seem to work when multiple items are passed

16 views
Skip to first unread message

Kuzhali Velmurugan

unread,
Feb 24, 2016, 12:05:17 AM2/24/16
to Hamcrest Developers
Hello,

Below is the scenario where am facing an issue. Here I am asserting that few Id's are not present:

given().param(param1, type)
.get(
"/API").then().log().ifValidationFails()
.body(
"entries.id", hasItems(id2, id3))
.body(
"entries.id", not(hasItems(id1, id2)))
.body(
SUCCESS, equalTo(true))
.assertThat().statusCode(
200);

It is expected to fail at not(hasItems(id1, id2)), as id2 is present. But the test seems to pass.
But not(hasItems()) seems to work fine when single Id is passed.

Kindly look into it.

Thanks,
Kuzhali

Jon Reid

unread,
Feb 24, 2016, 1:16:14 AM2/24/16
to hamcre...@googlegroups.com
Kuzhali,

hasItems is easy to confuse. Here's the documentation:

"Creates a matcher for Iterables that matches when consecutive passes over the examined Iterable yield at least one item that is equal to the corresponding item from the specified items."

So hasItems(id2, id3) is satisfied when any items satisfy equalTo(id2), and any items satisfy equalTo(id3).

not(hasItems(id1, id2)) is satisfied when hasItems(id1, id2) is not satisfied. 
Remember, hasItems(id1, id2) is satisfied when any items satisfy equalTo(id1), and any items satisfy equalTo(id2).
You say id2 is present. So there must be nothing satisfying equalTo(id1).

Hope this helps. 

Jon Reid
Jon Reid
Quality Coding
Twitter Facebook GitHub

--
You received this message because you are subscribed to the Google Groups "Hamcrest Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hamcrest-dev...@googlegroups.com.
To post to this group, send email to hamcre...@googlegroups.com.
Visit this group at https://groups.google.com/group/hamcrest-dev.
For more options, visit https://groups.google.com/d/optout.

Kuzhali Velmurugan

unread,
Feb 24, 2016, 1:58:28 AM2/24/16
to Hamcrest Developers
Yes, Thank you.
Reply all
Reply to author
Forward
0 new messages