### Question:
DefaultWorkbenchFeaturesMenusHelper { public TopLevelMenusBuilder<MenuBuilder> buildMenusFromNavTree(NavTree navTree) { if (navTree == null) { return null; } MenuBuilder<TopLevelMenusBuilder<MenuBuilder>> builder = null; for (NavItem navItem : navTree.getRootItems()) { if (navItem instanceof NavDivider) { continue; } if (navItem instanceof NavGroup && ((NavGroup) navItem).getChildren().isEmpty()) { continue; } if (builder == null) { builder = MenuFactory.newTopLevelMenu(navItem.getName()); } else { builder = builder.endMenu().newTopLevelMenu(navItem.getName()); } if (navItem instanceof NavGroup) { List<MenuItem> childItems = buildMenuItemsFromNavGroup((NavGroup) navItem); builder.withItems(childItems); } NavWorkbenchCtx navCtx = NavWorkbenchCtx.get(navItem); if (navCtx.getResourceId() != null && ActivityResourceType.PERSPECTIVE.equals(navCtx.getResourceType())) { PlaceRequest placeRequest = resolvePlaceRequest(navCtx.getResourceId()); builder = builder.place(placeRequest); } } return builder != null ? builder.endMenu() : null; } DefaultWorkbenchFeaturesMenusHelper(); @Inject  DefaultWorkbenchFeaturesMenusHelper(SyncBeanManager iocManager,
                                               ActivityManager activityManager,
                                               PerspectiveManager perspectiveManager,
                                               Caller<AuthenticationService> authService,
                                               User identity,
                                               UserMenu userMenu,
                                               UtilityMenuBar utilityMenuBar,
                                               WorkbenchMegaMenuPresenter menuBar,
                                               AboutCommand aboutCommand,
                                               AuthorizationManager authorizationManager,
                                               SessionInfo sessionInfo,
                                               PlaceManager placeManager); List<? extends MenuItem> getHomeViews(); List<MenuItem> getAuthoringViews(); List<? extends MenuItem> getProcessManagementViews(); List<? extends MenuItem> getExtensionsViews(); void addRolesMenuItems(); void addGroupsMenuItems(); void addWorkbenchViewModeSwitcherMenuItem(); void addWorkbenchConfigurationMenuItem(); void addUtilitiesMenuItems(); void addUserMenuItems(); String getDefaultPerspectiveIdentifier(); List<PerspectiveActivity> getPerspectiveActivities(); List<MenuItem> getPerspectivesMenuItems(); List<Menus> getRoles(); List<Menus> getGroups(); TopLevelMenusBuilder<MenuBuilder> buildMenusFromNavTree(NavTree navTree); List<MenuItem> buildMenuItemsFromNavGroup(NavGroup navGroup); PlaceRequest resolvePlaceRequest(String perspectiveId); static native void redirect(String url);  }### Answer:
@Test public void buildMenusFromNavTreeTest() { NavTree navTree = new NavTreeBuilder() .group("g1", "g1", "g1", true) .item("i1", "i1", "i1", true) .endGroup() .group("g2", "g2", "g2", true) .item("i2", "i2", "i2", true) .endGroup() .group("g3", "g3", "g3", true) .endGroup() .build(); Menus menus = menusHelper.buildMenusFromNavTree(navTree).build(); List<MenuItem> menuItems = menus.getItems(); assertEquals(menuItems.size(), 2); MenuGroup group1 = (MenuGroup) menuItems.get(0); assertEquals(group1.getCaption(), "g1"); assertEquals(group1.getItems().size(), 1); MenuItem item1 = group1.getItems().get(0); assertEquals(item1.getCaption(), "i1"); MenuGroup group2 = (MenuGroup) menuItems.get(1); assertEquals(group2.getCaption(), "g2"); assertEquals(group2.getItems().size(), 1); MenuItem item2 = group2.getItems().get(0); assertEquals(item2.getCaption(), "i2"); }