Using the Hamcrest library, I need to assert that a list of objects with specific properties (java beans) matches a set of properties. For example, if we had a list of Person objects with firstName, lastName, and middleName properties I've tried the following:
assertThat(personObjectList, either(contains(
hasProperty("firstName", is("Bob")),
hasProperty("lastName", is("Smith")),
hasProperty("middleName", is("R.")))
.or(contains(
hasProperty("firstName", is("Alex")),
hasProperty("lastName", is("Black")),
hasProperty("middleName", is("T."))));
But in execution the properties of the objects are not obtained, I just get a comparison against the Object T, output like:
but: was Person@7bd7c4cf, was Person@5b9df3b3
Is there a way to accomplish what I'm trying to do here using Hamcrest? This works when doing a single contains, but when doing two contains with either() I receive the output above.
Aucun commentaire:
Enregistrer un commentaire