4

I have a test with a collection of SpecialObject as result. SpecialObject has "name" and "surname" as properties. I want to test if the collection contains a specialObject with 2 specific properties, "name=myname" and "surname=lastname".

Here is what I have tried without success:

assertThat(result, Matchers.<SpecialObject>hasItem(
    allOf(
          hasProperty("name", equalTo("myname")),
          hasProperty("surname", equalTo("lastname"))
));
Slagathor
  • 852
  • 7
  • 23

1 Answers1

6

You can use both matcher to check if both properties has excepcted values.

    Assert.assertThat(result, Matchers.<SpecialObject>hasItem(
            Matchers.both(hasProperty("name", equalTo("myname")))
                    .and(hasProperty("surname", equalTo("lastname")))));
Vlad Bochenin
  • 3,007
  • 1
  • 20
  • 33