### Question:
MenuUtil { static IMenuService getSubMenuService(Map<String, IMenuService> menuMap) { int length = menuMap.size(); if (length == 0) return null; Iterator<IMenuService> it = menuMap.values().iterator(); IMenuService sub = null; while (it.hasNext()) { if (length == 1) return it.next(); IMenuService temp = it.next(); Class<? extends IMenuService> clazz = null; if (sub == null) { clazz = IMenuService.class; } else { clazz = sub.getClass(); } if (clazz.isAssignableFrom(temp.getClass())) { sub = temp; } } return sub; }  static String getMenusJson(String id, int level);  }### Answer:
@Test public void testGetSubMenuService() { Map<String, IMenuService> menuMap = new TreeMap<String, IMenuService>(); menuMap.put("1", new SubMenuService()); menuMap.put("2", new MenuService()); IMenuService menuService = MenuUtil.getSubMenuService(menuMap); Assert.assertEquals("获取菜单实例错误！", 1, menuService.getMenus("", 0).size()); }