How to assert that Set has item with exact property with hamcrest

Solution 1:

Well, you should try to let assertThat do the work for you.

Set<WhateverPropertyTypeYouAreUsing> expectedSet = Collections.singleton( ... create a property object with that id/value);

assertThat(mySet, is(expectedSet))

The restriction here: that assumes that your set contains only that one property value.

Otherwise, you can go for:

assertThat(mySet.contains(someProperty), is(true))

(probably with an additional message to better describe a failing assert).

Prereq: your property class should be implementing equals() in a reasonable manner.