MenuManager { @Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { if (event.getMenuAction() != MenuAction.RUNELITE && event.getMenuAction() != MenuAction.RUNELITE_PLAYER) { return; } int widgetId = event.getWidgetId(); Collection<WidgetMenuOption> options = managedMenuOptions.get(widgetId); for (WidgetMenuOption curMenuOption : options) { if (curMenuOption.getMenuTarget().equals(event.getMenuTarget()) && curMenuOption.getMenuOption().equals(event.getMenuOption())) { WidgetMenuOptionClicked customMenu = new WidgetMenuOptionClicked(); customMenu.setMenuOption(event.getMenuOption()); customMenu.setMenuTarget(event.getMenuTarget()); customMenu.setWidget(curMenuOption.getWidget()); eventBus.post(customMenu); return; } } String target = BOUNTY_EMBLEM_TAG_AND_TIER_REGEXP.matcher(event.getMenuTarget()).replaceAll(""); String username = Text.removeTags(target).split("[(]")[0].trim(); PlayerMenuOptionClicked playerMenuOptionClicked = new PlayerMenuOptionClicked(); playerMenuOptionClicked.setMenuOption(event.getMenuOption()); playerMenuOptionClicked.setMenuTarget(username); eventBus.post(playerMenuOptionClicked); } @Inject @VisibleForTesting  MenuManager(Client client, EventBus eventBus); void addManagedCustomMenu(WidgetMenuOption customMenuOption); void removeManagedCustomMenu(WidgetMenuOption customMenuOption); @Subscribe void onMenuEntryAdded(MenuEntryAdded event); void addPlayerMenuItem(String menuText); void removePlayerMenuItem(String menuText); @Subscribe void onPlayerMenuOptionsChanged(PlayerMenuOptionsChanged event); @Subscribe void onNpcActionChanged(NpcActionChanged event); @Subscribe void onMenuOptionClicked(MenuOptionClicked event);  }
@Test public void testPlayerMenuOptionClicked() { MenuOptionClicked event = new MenuOptionClicked(); event.setMenuAction(MenuAction.RUNELITE_PLAYER); event.setMenuTarget("username<col=40ff00> (level-42)"); menuManager.onMenuOptionClicked(event); ArgumentCaptor<PlayerMenuOptionClicked> captor = ArgumentCaptor.forClass(PlayerMenuOptionClicked.class); verify(eventBus).post(captor.capture()); PlayerMenuOptionClicked clicked = captor.getValue(); assertEquals("username", clicked.getMenuTarget()); }
@Test public void testPlayerMenuOptionWithBountyHunterEmblemClicked() { MenuOptionClicked event = new MenuOptionClicked(); event.setMenuAction(MenuAction.RUNELITE_PLAYER); event.setMenuTarget("username<img=20>5<col=40ff00> (level-42)"); menuManager.onMenuOptionClicked(event); ArgumentCaptor<PlayerMenuOptionClicked> captor = ArgumentCaptor.forClass(PlayerMenuOptionClicked.class); verify(eventBus).post(captor.capture()); PlayerMenuOptionClicked clicked = captor.getValue(); assertEquals("username", clicked.getMenuTarget()); }