@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(); }
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); }
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); } }
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(); }
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); }
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);  }