SimpleWorkbenchPanelPresenter extends AbstractDockingWorkbenchPanelPresenter<SimpleWorkbenchPanelPresenter> { @Override public void addPart(WorkbenchPartPresenter part) { SinglePartPanelHelper h = createSinglePartPanelHelper(); if (h.hasNoParts()) { super.addPart(part); } else { h.closeFirstPartAndAddNewOne(() -> super.addPart(part)); } } @Inject  SimpleWorkbenchPanelPresenter(@Named("SimpleWorkbenchPanelView") final WorkbenchPanelView<SimpleWorkbenchPanelPresenter> view,
                                         final PerspectiveManager perspectiveManager,
                                         final PlaceManager placeManager); @Override void addPart(WorkbenchPartPresenter part); @Override void addPart(WorkbenchPartPresenter part,
                        String contextId); @Override DockingWorkbenchPanelView<SimpleWorkbenchPanelPresenter> getPanelView();  }
@Test public void addPartTest() { WorkbenchPartPresenter part = mock(WorkbenchPartPresenter.class); when(part.getDefinition()).thenReturn(mock(PartDefinition.class)); presenter.addPart(part); verify(view).addPart(any()); }
@Test public void addPartTwiceShouldCloseOtherPartTest() { SinglePartPanelHelper singlePartPanelHelper = mock(SinglePartPanelHelper.class); SimpleWorkbenchPanelPresenter presenter = new SimpleWorkbenchPanelPresenter(view, mock(PerspectiveManager.class), placeManager) { SinglePartPanelHelper createSinglePartPanelHelper() { return singlePartPanelHelper; } }; presenter.init(); presenter.setDefinition(panelPresenterPanelDefinition); when(singlePartPanelHelper.hasNoParts()).thenReturn(false); WorkbenchPartPresenter part2 = mock(WorkbenchPartPresenter.class); when(part2.getDefinition()).thenReturn(mock(PartDefinition.class)); presenter.addPart(part2); verify(singlePartPanelHelper).closeFirstPartAndAddNewOne(any(Command.class)); }