@Test public void whenStepNotPassed() { when(first.execute(any())).thenReturn(false); reset(first); StatefulCommand statefulCommand = new StatefulCommand(first); CommandExecution commandExecution = commandExecution(false); statefulCommand.execute(commandExecution); verify(first).prompt(eq(commandExecution)); reset(first); statefulCommand.execute(commandExecution); verify(first).execute(eq(commandExecution)); verify(first).prompt(eq(commandExecution)); verify(second, times(0)).execute(any()); }
@Override public void execute(CommandExecution commandExecution) { final UUID id = commandExecution.getSender().getId(); CommandStep currentState = userStates.getIfPresent(id); Optional<CommandStep> nextState = this.computeNextState(commandExecution, currentState); if (nextState.isPresent()) { this.userStates.put(id, nextState.get()); } else { this.userStates.invalidate(id); } }
StatefulCommand implements Command { @Override public void execute(CommandExecution commandExecution) { final UUID id = commandExecution.getSender().getId(); CommandStep currentState = userStates.getIfPresent(id); Optional<CommandStep> nextState = this.computeNextState(commandExecution, currentState); if (nextState.isPresent()) { this.userStates.put(id, nextState.get()); } else { this.userStates.invalidate(id); } } }
StatefulCommand implements Command { @Override public void execute(CommandExecution commandExecution) { final UUID id = commandExecution.getSender().getId(); CommandStep currentState = userStates.getIfPresent(id); Optional<CommandStep> nextState = this.computeNextState(commandExecution, currentState); if (nextState.isPresent()) { this.userStates.put(id, nextState.get()); } else { this.userStates.invalidate(id); } } StatefulCommand(CommandStep initialState); }
StatefulCommand implements Command { @Override public void execute(CommandExecution commandExecution) { final UUID id = commandExecution.getSender().getId(); CommandStep currentState = userStates.getIfPresent(id); Optional<CommandStep> nextState = this.computeNextState(commandExecution, currentState); if (nextState.isPresent()) { this.userStates.put(id, nextState.get()); } else { this.userStates.invalidate(id); } } StatefulCommand(CommandStep initialState); @Override void execute(CommandExecution commandExecution); }
StatefulCommand implements Command { @Override public void execute(CommandExecution commandExecution) { final UUID id = commandExecution.getSender().getId(); CommandStep currentState = userStates.getIfPresent(id); Optional<CommandStep> nextState = this.computeNextState(commandExecution, currentState); if (nextState.isPresent()) { this.userStates.put(id, nextState.get()); } else { this.userStates.invalidate(id); } } StatefulCommand(CommandStep initialState); @Override void execute(CommandExecution commandExecution);  }