ListBarWidgetImpl extends ResizeComposite implements ListBarWidget { protected Widget makeItem(final MenuItem item, boolean isRoot) { Widget[] menuWidget = new Widget[]{null}; item.accept(new AuthFilterMenuVisitor(authzManager, identity, new BaseMenuVisitor() { @Override public boolean visitEnter(MenuGroup menuGroup) { menuWidget[0] = makeMenuGroup(menuGroup, isRoot); return false; } @Override public void visit(MenuItemCommand menuItemCommand) { menuWidget[0] = makeMenuItemCommand(menuItemCommand, isRoot); } @Override public void visit(MenuCustom<?> menuCustom) { menuWidget[0] = makeMenuCustom(menuCustom); } })); return menuWidget[0]; }  @Override void enableDnd(); @Override void disableDnd(); @Override void setPresenter(final WorkbenchPanelPresenter presenter); @Override void setDndManager(final WorkbenchDragAndDropManager dndManager); @Override void clear(); @Override void addPart(final WorkbenchPartPresenter.View view); @Override void changeTitle(final PartDefinition part,
                            final String title,
                            final IsWidget titleDecoration); @Override boolean selectPart(final PartDefinition part); @Override boolean remove(final PartDefinition part); @Override void setFocus(final boolean hasFocus); @Override void addOnFocusHandler(final Command command); @Override int getPartsSize(); @Override Collection<PartDefinition> getParts(); @Override HandlerRegistration addBeforeSelectionHandler(final BeforeSelectionHandler<PartDefinition> handler); @Override HandlerRegistration addSelectionHandler(final SelectionHandler<PartDefinition> handler); @Override void onResize(); @Override MaximizeToggleButtonPresenter getMaximizeButton(); @Override boolean isDndEnabled(); @Override void enableClosePart(); @Override void disableClosePart(); @Override void disableExpandPart();  }
@Test public void testSingleMenu() { final String caption = "test"; final Menus menus = MenuFactory.newTopLevelMenu(caption).respondsWith(() -> { }).endMenu().build(); final Widget widget = listBar.makeItem(menus.getItems().get(0), true); assertTrue(widget instanceof Button); verify((Button) widget).setText(caption); }
@Test public void testSubMenus() { final String caption = "test"; final String submenu1 = "submenu1"; final String submenu2 = "submenu2"; final Menus menus = MenuFactory.newTopLevelMenu(caption) .menus() .menu(submenu1).respondsWith(() -> { }).endMenu() .menu(submenu2).respondsWith(() -> { }).endMenu() .endMenus() .endMenu() .build(); final Widget widget = listBar.makeItem(menus.getItems().get(0), true); assertTrue(widget instanceof ButtonGroup); ArgumentCaptor<Widget> buttonCaptor = ArgumentCaptor.forClass(Widget.class); verify(((ButtonGroup) widget), times(2)).add(buttonCaptor.capture()); final List<Widget> widgetList = buttonCaptor.getAllValues(); assertEquals(2, widgetList.size()); verify((Button) widgetList.get(0)).setText(caption); ArgumentCaptor<Widget> dropCaptor = ArgumentCaptor.forClass(Widget.class); verify((DropDownMenu) widgetList.get(1), times(2)).add(dropCaptor.capture()); final List<Widget> subMenusWidgetList = dropCaptor.getAllValues(); assertEquals(2, subMenusWidgetList.size()); verify((AnchorListItem) subMenusWidgetList.get(0)).setText(submenu1); verify((AnchorListItem) subMenusWidgetList.get(1)).setText(submenu2); }