MultiPageEditorViewImpl extends ResizeTabPanel implements MultiPageEditorView { @Override public int getPageIndex(final String title) { final int tabsCount = getTabBar().getWidgetCount(); for (int tabIndex = 0; tabIndex < tabsCount; tabIndex++) { if (getTabBar().getWidget(tabIndex) instanceof TabListItem) { final TabListItem tab = (TabListItem) getTabBar().getWidget(tabIndex); if (Objects.equals(tab.getText(), title)) { return tabIndex; } } } throw new IllegalArgumentException("Page with title: '" + title + "' doesn't exist."); }  @Override void init(); void enableSelectedPageEvent(final Event<MultiPageEditorSelectedPageEvent> selectedPageEvent); void addPage(final Page page); @Override void addPage(int index, final Page page); void selectPage(int index); int selectedPage(); @Override void disablePage(int index); @Override void enablePage(int index); @Override int getPageIndex(final String title);  }
@Test public void testGetPageIndex() { final NavTabs navTabs = mock(NavTabs.class); doReturn(navTabs).when(view).getTabBar(); final TabListItem pageOne = mock(TabListItem.class); final TabListItem pageTwo = mock(TabListItem.class); final TabListItem pageThree = mock(TabListItem.class); doReturn(3).when(navTabs).getWidgetCount(); doReturn(pageOne).when(navTabs).getWidget(0); doReturn(pageTwo).when(navTabs).getWidget(1); doReturn(pageThree).when(navTabs).getWidget(2); doReturn("page 1").when(pageOne).getText(); doReturn("page 2").when(pageTwo).getText(); doReturn("page 3").when(pageThree).getText(); Assertions.assertThat(view.getPageIndex("page 3")).isEqualTo(2); Assertions.assertThat(view.getPageIndex("page 2")).isEqualTo(1); Assertions.assertThat(view.getPageIndex("page 1")).isEqualTo(0); Assertions.assertThatThrownBy(() -> view.getPageIndex("xyz")) .hasMessage("Page with title: 'xyz' doesn't exist."); }