@Test public void setCurrentContextNoSimulationNoBackground() { final ScenarioSimulationContext.Status status = scenarioSimulationContextLocal.getStatus(); commandSpy.restorableStatus = status; commandSpy.restorableStatus.setSimulation(null); commandSpy.restorableStatus.setBackground(null); final CommandResult<ScenarioSimulationViolation> retrieved = commandSpy.setCurrentContext(scenarioSimulationContextLocal); assertEquals(CommandResult.Type.ERROR, retrieved.getType()); verify(scenarioGridModelMock, never()).clearSelections(); verify(backgroundGridModelMock, never()).clearSelections(); verify(scenarioGridMock, never()).setContent(eq(simulationMock), eq(scenarioSimulationContextLocal.getSettings().getType())); verify(scenarioSimulationModelMock, never()).setSimulation(eq(simulationMock)); verify(backgroundGridMock, never()).setContent(eq(simulationMock), eq(scenarioSimulationContextLocal.getSettings().getType())); verify(scenarioSimulationModelMock, never()).setBackground(eq(backgroundMock)); verify(scenarioSimulationEditorPresenterMock, never()).reloadTestTools(eq(true)); verify(commandSpy, never()).commonExecution(eq(scenarioSimulationContextLocal)); assertEquals(status, commandSpy.restorableStatus); }
protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) { try { final Simulation simulationToRestore = restorableStatus.getSimulation(); final Background backgroundToRestore = restorableStatus.getBackground(); if (simulationToRestore == null) { throw new IllegalStateException("Simulation is null in restorable status"); } if (backgroundToRestore == null) { throw new IllegalStateException("Background is null in restorable status"); } final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus(); context.getSimulationGrid().getModel().clearSelections(); context.getBackgroundGrid().getModel().clearSelections(); context.getSimulationGrid().setContent(simulationToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore); context.getBackgroundGrid().setContent(backgroundToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore); context.getScenarioSimulationEditorPresenter().reloadTestTools(true); context.setStatus(restorableStatus); restorableStatus = originalStatus; return commonExecution(context); } catch (Exception e) { return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage()))); } }
AbstractScenarioGridCommand extends AbstractScenarioSimulationCommand { protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) { try { final Simulation simulationToRestore = restorableStatus.getSimulation(); final Background backgroundToRestore = restorableStatus.getBackground(); if (simulationToRestore == null) { throw new IllegalStateException("Simulation is null in restorable status"); } if (backgroundToRestore == null) { throw new IllegalStateException("Background is null in restorable status"); } final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus(); context.getSimulationGrid().getModel().clearSelections(); context.getBackgroundGrid().getModel().clearSelections(); context.getSimulationGrid().setContent(simulationToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore); context.getBackgroundGrid().setContent(backgroundToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore); context.getScenarioSimulationEditorPresenter().reloadTestTools(true); context.setStatus(restorableStatus); restorableStatus = originalStatus; return commonExecution(context); } catch (Exception e) { return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage()))); } } }
AbstractScenarioGridCommand extends AbstractScenarioSimulationCommand { protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) { try { final Simulation simulationToRestore = restorableStatus.getSimulation(); final Background backgroundToRestore = restorableStatus.getBackground(); if (simulationToRestore == null) { throw new IllegalStateException("Simulation is null in restorable status"); } if (backgroundToRestore == null) { throw new IllegalStateException("Background is null in restorable status"); } final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus(); context.getSimulationGrid().getModel().clearSelections(); context.getBackgroundGrid().getModel().clearSelections(); context.getSimulationGrid().setContent(simulationToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore); context.getBackgroundGrid().setContent(backgroundToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore); context.getScenarioSimulationEditorPresenter().reloadTestTools(true); context.setStatus(restorableStatus); restorableStatus = originalStatus; return commonExecution(context); } catch (Exception e) { return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage()))); } } protected  AbstractScenarioGridCommand(final GridWidget gridWidget); protected  AbstractScenarioGridCommand(); }
AbstractScenarioGridCommand extends AbstractScenarioSimulationCommand { protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) { try { final Simulation simulationToRestore = restorableStatus.getSimulation(); final Background backgroundToRestore = restorableStatus.getBackground(); if (simulationToRestore == null) { throw new IllegalStateException("Simulation is null in restorable status"); } if (backgroundToRestore == null) { throw new IllegalStateException("Background is null in restorable status"); } final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus(); context.getSimulationGrid().getModel().clearSelections(); context.getBackgroundGrid().getModel().clearSelections(); context.getSimulationGrid().setContent(simulationToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore); context.getBackgroundGrid().setContent(backgroundToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore); context.getScenarioSimulationEditorPresenter().reloadTestTools(true); context.setStatus(restorableStatus); restorableStatus = originalStatus; return commonExecution(context); } catch (Exception e) { return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage()))); } } 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 { protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) { try { final Simulation simulationToRestore = restorableStatus.getSimulation(); final Background backgroundToRestore = restorableStatus.getBackground(); if (simulationToRestore == null) { throw new IllegalStateException("Simulation is null in restorable status"); } if (backgroundToRestore == null) { throw new IllegalStateException("Background is null in restorable status"); } final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus(); context.getSimulationGrid().getModel().clearSelections(); context.getBackgroundGrid().getModel().clearSelections(); context.getSimulationGrid().setContent(simulationToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore); context.getBackgroundGrid().setContent(backgroundToRestore, context.getSettings().getType()); context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore); context.getScenarioSimulationEditorPresenter().reloadTestTools(true); context.setStatus(restorableStatus); restorableStatus = originalStatus; return commonExecution(context); } catch (Exception e) { return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage()))); } } 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);  }