I have the following scenario, where I want to test someFunction():
Collection<MyObject> objects = someFunction(someInput);
assertThat(objects , contains(hasProperty("property", is(propertyIWantToTest))));
This works fine if Collection<MyObject> objects
should have just 1 MyObject object
according to someInput
which is passed to someFunction()
.
However, there are some cases for someInput
that the Collection<MyObject> objects
should have 2 or more MyObject object
containg the same propertyIWantToTest
object.
Is there a way to use Hamcrest matchers to test that?
Here's something closer to what I'm willing to achieve:
assertThat(objects , contains(exactlyTwoTimes(hasProperty("property", is(propertyIWantToTest)))));