I have a Java Custom Object collection List<Employee>
with two (2) properties. It is received as a response of Web Service. The object seems like
public class Employee{
public String getName(){ ... }
public String getDesignation(){ ... }
}
I need to write an assertion to check if the name of the employee is David then its designation must be Manager. I tried it like that
assertThat(employeeList, allOf(hasItem(hasProperty("name", equalTo("David")))
, hasItem(hasProperty("designation", equalTo("Manager")))));
but it passed if there is at least one Manager instance and one David. My requirement is to apply these two checks on a single instance.
Please help.
Given a class
Foo
:And a custom Hamcrest matcher:
This test will pass: