### Question:
HibernateMenuDAO extends HibernatePersistentObjectDAO<Menu> implements MenuDAO { @Override public boolean applyRightToTree(long id) { boolean result = true; try { Menu parent = findById(id); Long securityRef = id; if (parent.getSecurityRef() != null) securityRef = parent.getSecurityRef(); List<Menu> children = findChildren(id, null); for (Menu menu : children) { if (!securityRef.equals(menu.getSecurityRef())) { menu.setSecurityRef(securityRef); menu.getMenuGroups().clear(); store(menu); } applyRightToTree(menu.getId()); } } catch (Throwable e) { if (log.isErrorEnabled()) log.error(e.getMessage(), e); result = false; } 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 testApplyRightsToTree() { User user = new User(); user.setId(4); Menu menu = dao.findById(1041); Assert.assertTrue(null == menu.getSecurityRef()); Assert.assertTrue(dao.applyRightToTree(101)); menu = dao.findById(104); Assert.assertTrue(101 == menu.getSecurityRef()); menu = dao.findById(1041); Assert.assertTrue(101 == menu.getSecurityRef()); }