@Test
public void findAllNameSort() throws SQLException {

    // Retrieve groups sorted by name
    List<Group> groups = groupService.findAll(context, null);
    assertThat("findAllNameSort 1", groups, notNullValue());
    // Add all group names to two arraylists (arraylists are unsorted)
    // NOTE: we use lists here because we don't want duplicate names removed
    List<String> names = new ArrayList<>();
    List<String> sortedNames = new ArrayList<>();
    for (Group group : groups) {
        // Ignore any unnamed groups. This is only necessary when running unit tests via a persistent database (e.g. Postgres) as unnamed groups may be created by other tests.
        if (group.getName() == null) {
            continue;
        }
        names.add(group.getName());
        sortedNames.add(group.getName());
    }
    // Now, sort the "sortedNames" Arraylist
    Collections.sort(sortedNames);
    // Verify the sorted arraylist is still equal to the original (unsorted) one
    assertEquals("findAllNameSort compareLists", sortedNames, names);
}