I am attempting to test a Spring MVC controller method used to capture a person's details.The Person entity has a a List representing the person's roles.
On the UI the roles are selected via dropdown and captured in a List. In the test I would like to assert that there is a corresponding PersonRole for each role submitted on the dropdown.
I have written a utility method to assert the values are as expected :
public static void AssertPerson(Person person, Long accountId, String userName, String firstName, String lastName, List<String> roles) {
Assert.assertEquals(accountId, person.getAccount().getId());
Assert.assertEquals(userName, person.getUsername());
Assert.assertEquals(firstName, person.getFirstname());
Assert.assertEquals(lastName, person.getSurname());
for(PersonRole personRole : person.getRoleList()) {
Assert.assertTrue(roles.contains(personRole.getName()))
}
}
How am I supposed to avoid this for loop?