TabContainerViewImpl extends Composite implements TabContainerView { @Override public void showTab(@NotNull Tab tab) { for (TabPresenter tabPresenter : visiblePresenters) { tabPresenter.setVisible(false); } for (TabPresenter tabPresenter : removablePresenters) { mainPanel.remove(tabPresenter.getView()); } TabPresenter presenter = tab.getTab(); if (tab.isRemovable()) { removablePresenters.add(presenter); mainPanel.add(presenter.getView()); } else if (!visiblePresenters.contains(presenter)) { visiblePresenters.add(presenter); mainPanel.add(presenter.getView()); } else { presenter.setVisible(true); } } @Inject  TabContainerViewImpl(RunnerResources resources, WidgetFactory widgetFactory); @Override void showTab(@NotNull Tab tab); @Override void selectTab(@NotNull Tab tab); @Override void setVisibleTitle(@NotNull Map<String, Boolean> tabVisibilities); @Override void addTab(@NotNull Tab tab); @Override void showTabTitle(@NotNull String tabName, boolean isShown); @Override void setDelegate(ActionDelegate actionDelegate);  }
@Test public void shouldShowRemovableTab() { when(tab1.isRemovable()).thenReturn(true); tabContainerView.showTab(tab1); verify(tab1).getTab(); verify(tab1).isRemovable(); verify(tabPresenter1).getView(); verify(tabContainerView.mainPanel).add(isWidget1); }
@Test public void shouldShowTabAndRemoveRemovableTab() { when(tab1.isRemovable()).thenReturn(true); when(tab2.isRemovable()).thenReturn(false); addThreeTabs(); tabContainerView.showTab(tab1); tabContainerView.showTab(tab2); verify(tabContainerView.mainPanel).remove(isWidget1); verify(tab1).getTab(); verify(tab1).isRemovable(); verify(tabPresenter1, times(2)).getView(); verify(tabContainerView.mainPanel).add(isWidget1); verify(tab2).getTab(); verify(tab2).isRemovable(); verify(tabPresenter2).getView(); verify(tabContainerView.mainPanel).add(isWidget2); }
@Test public void shouldShowNotRemovableTabWhichIsAlreadyShown() { when(tab1.isRemovable()).thenReturn(false); tabContainerView.showTab(tab1); tabContainerView.showTab(tab1); verify(tabPresenter1).setVisible(false); verify(tabPresenter1).setVisible(true); verify(tab1, times(2)).getTab(); verify(tab1, times(2)).isRemovable(); verify(tabPresenter1).getView(); verify(tabContainerView.mainPanel).add(isWidget1); }