### Question:
HibernateMenuDAO extends HibernatePersistentObjectDAO<Menu> implements MenuDAO { @Override public List<Menu> findByGroupId(long groupId) { List<Menu> coll = new ArrayList<Menu>(); if (groupId == Group.GROUPID_ADMIN) return findAll(); try { StringBuffer query = new StringBuffer("select distinct(_entity) from Menu _entity "); query.append(" left join _entity.menuGroups as _group "); query.append(" where _entity.deleted=0 and _group.groupId =" + groupId); coll = (List<Menu>) findByQuery(query.toString(), null, null); if (!coll.isEmpty()) { StringBuffer query2 = new StringBuffer("select _entity from Menu _entity where _entity.deleted=0 "); query2.append(" and _entity.securityRef in ("); boolean first = true; for (Menu menu : coll) { if (!first) query2.append(","); query2.append(Long.toString(menu.getId())); first = false; } query2.append(")"); List<Menu> coll2 = (List<Menu>) findByQuery(query2.toString(), null, null); for (Menu menu : coll2) { if (!coll.contains(menu)) coll.add(menu); } } } catch (Exception e) { log.error(e.getMessage(), e); } return coll; } protected  HibernateMenuDAO(); UserDAO getUserDAO(); void setUserDAO(UserDAO userDAO); @Override boolean store(Menu menu); @Override @SuppressWarnings("rawtypes") List<Menu> findByUserId(long userId); @Override List<Menu> findByUserId(long userId, long parentId); @SuppressWarnings("rawtypes") List<Menu> findByUserId(long userId, long parentId, Integer type); @Override List<Menu> findChildren(long parentId, Integer max); @SuppressWarnings("rawtypes") @Override List<Menu> findChildren(long parentId, long userId); List<Menu> findByParentId(long parentId); @Override @SuppressWarnings("rawtypes") boolean isWriteEnable(long menuId, long userId); @Override @SuppressWarnings("rawtypes") boolean isReadEnable(long menuId, long userId); @Override String findNameById(long menuId); @Override List<Long> findMenuIdByUserId(long userId); int isMenuWriteable(long menuId, long userId); @Override boolean hasWriteAccess(Menu menu, long userId); @Override List<Menu> findByGroupId(long groupId); @SuppressWarnings("rawtypes") List<Long> findIdByUserId(long userId, long parentId, Integer type); @Override List<Menu> findByName(String name); @Override List<Menu> findByName(Menu parent, String name, boolean caseSensitive); @Override String computePathExtended(long menuId); @Override List<Menu> findByNameAndParentId(String name, long parentId); @Override List<Menu> findParents(long menuId); @Override void restore(long menuId, boolean parents); @Override List<Long> findMenuIdByUserIdAndPermission(long userId, Permission permission); @Override void deleteAll(Collection<Menu> menus); @Override boolean delete(long menuId, int code); @Override boolean applyRightToTree(long id); @SuppressWarnings("rawtypes") @Override List<Long> findIdByUserId(long userId, long parentId);  }### Answer:
@Test public void testFindByGroupId() { Collection<Menu> menus = dao.findByGroupId(1); Assert.assertEquals(dao.findAllIds().size(), menus.size()); menus = dao.findByGroupId(10); Assert.assertEquals(0, menus.size()); menus = dao.findByGroupId(2); Assert.assertTrue(menus.contains(dao.findById(104))); Assert.assertTrue(menus.contains(dao.findById(1200))); }