I have a Unit Test for a service method that returns an HashSet<T>
and I get it in the test method as shown below:
Set<EmployeeDTO> result = employeeService.findAllByUuid(uuid);
// I also convert the set to list for accessing by index:
List<EmployeeDTO> resultList = new ArrayList<>(result);
And try to assert as shown below:
assertEquals("Hans", resultList.get(0).getName());
However, there are 2 elements in the resultset and as expected, the order in the HashSet
is changing. In this scene, how should I make assertions when I receive HashSet
as return type of the tested method?