0

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?

  • 2
    Possible duplicate of [Assert List in Junit](http://stackoverflow.com/questions/3236880/assert-list-in-junit) – Atri Jan 08 '16 at 05:50
  • ```Assert.assertTrue(roles.containsAll(person.getRoleList()));```? –  Jan 08 '16 at 05:57
  • Thats a nice feature I didn't know about. It doesn't suit my needs 100% though because I am comparing a List to a List – Duran Wesley Harris Jan 08 '16 at 06:19

0 Answers0