ApiGrouperDaoImpl extends AbstractGrouperDaoImpl implements ApiGrouperDao { protected String formatAllTeamsSQLWithSortByOption(String sortBy) { String sql = SQL_FIND_ALL_TEAMS_BY_MEMBER_SORTED; if (!StringUtils.isBlank(sortBy)) { String sortByColumn = null; Set<Entry<String, String>> entrySet = VALID_SORTS_FOR_TEAM_QUERY.entrySet(); for (Entry<String, String> entry : entrySet) { if (entry.getKey().equals(sortBy)) { sortByColumn = entry.getValue(); break; } } Assert.isTrue(!StringUtils.isBlank(sortByColumn), "The only supported sortBy options are (" + VALID_SORTS_FOR_TEAM_QUERY.keySet() + "). Not allowed is '" + sortBy + "'"); sql = String.format(sql, sortByColumn); } else { sql = String.format(sql, "name"); } return sql; }  Group20Entry findGroup20(String personId, String groupName); Group20Entry findAllGroup20sByMember(String personId, Integer offset, Integer pageSize, String sortBy); void setJdbcTemplate(JdbcTemplate jdbcTemplate); @Override GroupMembersEntry findAllMembers(String groupId, Integer offset, Integer pageSize); @Override Group20Entry findGroups20ByIds(String personId, String[] groupIds, Integer pageSize, Integer offset); void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate);  }
@Test public void sortByOptions() { ApiGrouperDaoImpl daoImpl = new ApiGrouperDaoImpl(); String sql = daoImpl.formatAllTeamsSQLWithSortByOption(null); assertTrue(sql.endsWith("order by gg.name limit ? offset ?")); try { daoImpl.formatAllTeamsSQLWithSortByOption("wtf"); fail(); } catch (RuntimeException e) { } sql = daoImpl.formatAllTeamsSQLWithSortByOption("title"); assertTrue(sql.endsWith("order by gg.display_name limit ? offset ?")); }