### Question:
HibernateMenuDAO extends HibernatePersistentObjectDAO<Menu> implements MenuDAO { @Override public boolean store(Menu menu) throws PersistenceException { boolean result = true; try { if (menu.getSecurityRef() != null) menu.getMenuGroups().clear(); GroupDAO gDao = (GroupDAO) Context.get().getBean(GroupDAO.class); Iterator<MenuGroup> iter = menu.getMenuGroups().iterator(); while (iter.hasNext()) { MenuGroup mg = iter.next(); Group group = gDao.findById(mg.getGroupId()); if (group.isGuest() && !Menu.admittedGuestMenuIds.contains(menu.getId())) iter.remove(); } saveOrUpdate(menu); } catch (Throwable e) { throw new PersistenceException(e); } return result; } 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 testStore() throws PersistenceException { Menu menu = new Menu(); menu.setName("text"); menu.setParentId(2); menu.setMenuGroup(new long[] { 1, 2 }); Assert.assertTrue(dao.store(menu)); menu = dao.findById(2000); Assert.assertEquals("menu.adminxxx", menu.getName()); Assert.assertEquals(1, menu.getMenuGroups().size()); menu = dao.findById(9); Assert.assertEquals("security", menu.getName()); dao.store(menu); menu = dao.findById(101); menu.setName("pippo"); Assert.assertTrue(dao.store(menu)); menu = dao.findById(102); Assert.assertNotNull(menu); menu = dao.findById(101); menu.setName("pippo2"); Assert.assertTrue(dao.store(menu)); menu = dao.findById(102); menu = dao.findById(102); Assert.assertTrue(dao.store(menu)); }