AbstractScenarioGridCommand extends AbstractScenarioSimulationCommand { public Optional<CommandResult<ScenarioSimulationViolation>> commonUndoRedoPreexecution(final ScenarioSimulationContext context) { final Optional<GridWidget> selectedGridWidgetOptional = context.getSelectedGridWidget(); if (selectedGridWidgetOptional.isPresent() && Objects.equals(gridWidget, selectedGridWidgetOptional.get())) { return Optional.empty(); } switch (gridWidget) { case SIMULATION: context.getScenarioSimulationEditorPresenter().selectSimulationTab(); break; case BACKGROUND: context.getScenarioSimulationEditorPresenter().selectBackgroundTab(); break; default: throw new IllegalStateException("Illegal GridWidget " + gridWidget); } context.getScenarioGridPanelByGridWidget(gridWidget).onResize(); context.getScenarioGridPanelByGridWidget(gridWidget).select(); return Optional.of(CommandResultBuilder.SUCCESS); } protected  AbstractScenarioGridCommand(final GridWidget gridWidget); protected  AbstractScenarioGridCommand(); @Override CommandResult<ScenarioSimulationViolation> execute(ScenarioSimulationContext context); @Override CommandResult<ScenarioSimulationViolation> undo(ScenarioSimulationContext context); CommandResult<ScenarioSimulationViolation> redo(ScenarioSimulationContext context); Optional<CommandResult<ScenarioSimulationViolation>> commonUndoRedoPreexecution(final ScenarioSimulationContext context);  }
@Test public void commonUndoRedoPreexecutionSameGrid() { when(backgroundGridWidgetSpy.isSelected()).thenReturn(false); when(scenarioGridWidgetSpy.isSelected()).thenReturn(true); commandSpy.gridWidget = GridWidget.SIMULATION; final Optional<CommandResult<ScenarioSimulationViolation>> retrieved = commandSpy.commonUndoRedoPreexecution(scenarioSimulationContextLocal); assertFalse(retrieved.isPresent()); verify(scenarioGridPanelMock, never()).onResize(); verify(scenarioGridPanelMock, never()).select(); }
@Test public void commonUndoRedoPreexecutionDifferentGridSIMULATION() { when(backgroundGridWidgetSpy.isSelected()).thenReturn(true); when(scenarioGridWidgetSpy.isSelected()).thenReturn(false); commandSpy.gridWidget = GridWidget.SIMULATION; final Optional<CommandResult<ScenarioSimulationViolation>> retrieved = commandSpy.commonUndoRedoPreexecution(scenarioSimulationContextLocal); assertTrue(retrieved.isPresent()); assertEquals(CommandResult.Type.INFO, retrieved.get().getType()); verify(scenarioGridPanelMock, times(1)).onResize(); verify(scenarioGridPanelMock, times(1)).select(); }
@Test public void commonUndoRedoPreexecutionDifferentGridBACKGROUND() { when(backgroundGridWidgetSpy.isSelected()).thenReturn(false); when(scenarioGridWidgetSpy.isSelected()).thenReturn(true); commandSpy.gridWidget = GridWidget.BACKGROUND; final Optional<CommandResult<ScenarioSimulationViolation>> retrieved = commandSpy.commonUndoRedoPreexecution(scenarioSimulationContextLocal); assertTrue(retrieved.isPresent()); assertEquals(CommandResult.Type.INFO, retrieved.get().getType()); verify(backgroundGridPanelMock, times(1)).onResize(); verify(backgroundGridPanelMock, times(1)).select(); }
@Test public void commonUndoRedoPreexecutionDifferentGridCheckSwitch() { for (GridWidget gridWidget : GridWidget.values()) { when(scenarioGridWidgetSpy.isSelected()).thenReturn(GridWidget.BACKGROUND.equals(gridWidget)); when(backgroundGridWidgetSpy.isSelected()).thenReturn(GridWidget.SIMULATION.equals(gridWidget)); commandSpy.gridWidget = gridWidget; commandSpy.commonUndoRedoPreexecution(scenarioSimulationContextLocal); } }