MultiScreenMenuBuilder implements Function<MenuItem, Optional<HTMLElement>> { @Override public Optional<HTMLElement> apply(final MenuItem menuItem) { return Optional.ofNullable(makeItem(menuItem, true)); }  @Override Optional<HTMLElement> apply(final MenuItem menuItem);  }
@Test public void testDeniedPermission() { final MenuItem menuItem = mock(MenuItem.class); when(authManager.authorize(any(Resource.class), eq(identity))).thenReturn(false); final Optional<HTMLElement> optional = menuBuilder.apply(menuItem); assertFalse(optional.isPresent()); verify(authManager).authorize(menuItem, identity); verifyZeroInteractions(kebabMenus, document); }
@Test public void testAllowedPermission() { final MenuItem menuItem = mock(MenuItem.class); when(authManager.authorize(any(Resource.class), eq(identity))).thenReturn(false); when(authManager.authorize(menuItem, identity)).thenReturn(true); final Optional<HTMLElement> optional = menuBuilder.apply(menuItem); assertFalse(optional.isPresent()); verify(authManager).authorize(menuItem, identity); verifyZeroInteractions(kebabMenus, document); }
@Test public void testMenuItemCommand() { final MenuItemCommand menuItem = mock(MenuItemCommand.class); final Optional<HTMLElement> optional = menuBuilder.apply(menuItem); assertTrue(optional.isPresent()); verify(buttons).get(); verifyZeroInteractions(kebabMenus); }
@Test public void testMenuGroup() { final KebabMenu kebabMenu = mock(KebabMenu.class); when(kebabMenu.getElement()).thenReturn(mock(HTMLDivElement.class)); when(kebabMenus.get()).thenReturn(kebabMenu); final MenuGroup menuItem = mock(MenuGroup.class); final Optional<HTMLElement> optional = menuBuilder.apply(menuItem); assertTrue(optional.isPresent()); verify(kebabMenus).get(); verifyZeroInteractions(document); }
@Test public void testMenuCustom() { final MenuCustom menuItem = mock(MenuCustom.class); when(menuItem.build()).thenReturn(mock(HTMLElement.class)); final Optional<HTMLElement> optional = menuBuilder.apply(menuItem); assertTrue(optional.isPresent()); verify(menuItem).build(); verifyZeroInteractions(kebabMenus, document); }