@Test public void execute() { CommandOptionsValidator validator = mock(CommandOptionsValidator.class); SendMessage sendMessage = mock(SendMessage.class); CommandExecutor commandExecutor = new CommandExecutor( sendMessage, validator ); when(validator.validate(any(), any(), any())).thenReturn(Optional.empty()); Command command= mock(Command.class); CommandOptions commandOptions = mock(CommandOptions.class); CommandRegistration commandRegistration = new CommandRegistration( command, commandOptions ); commandExecutor.execute(commandRegistration, mock(Sender.class), new String[]{"body", "arg1", "arg2"}); verify(command).execute(argThat(execution -> { ArgumentSet arguments = execution.getArguments(); return execution.getBody().equals("body") && arguments.getAll().equals(Arrays.asList("arg1", "arg2")); })); }
public void execute(CommandRegistration commandContainer, Sender sender, String[] arguments) { Command command = commandContainer.getCommand(); Optional<Message> validationErrorMessage = validator.validate(commandContainer.getCommandOptions(), arguments, sender); if (validationErrorMessage.isPresent()) { sendMessage.to(sender.getId(), validationErrorMessage.get()); sendMessage.to(sender.getId(), commandContainer.getCommandOptions().getUsage()); } else { List<String> argumentCollection = Arrays.asList(arguments).subList(1, arguments.length); command.execute( new StaticCommandExecution(sender, new ValidatingArgumentSet( new ListArgumentSet(argumentCollection)), arguments[0])); } }
CommandExecutor { public void execute(CommandRegistration commandContainer, Sender sender, String[] arguments) { Command command = commandContainer.getCommand(); Optional<Message> validationErrorMessage = validator.validate(commandContainer.getCommandOptions(), arguments, sender); if (validationErrorMessage.isPresent()) { sendMessage.to(sender.getId(), validationErrorMessage.get()); sendMessage.to(sender.getId(), commandContainer.getCommandOptions().getUsage()); } else { List<String> argumentCollection = Arrays.asList(arguments).subList(1, arguments.length); command.execute( new StaticCommandExecution(sender, new ValidatingArgumentSet( new ListArgumentSet(argumentCollection)), arguments[0])); } } }
CommandExecutor { public void execute(CommandRegistration commandContainer, Sender sender, String[] arguments) { Command command = commandContainer.getCommand(); Optional<Message> validationErrorMessage = validator.validate(commandContainer.getCommandOptions(), arguments, sender); if (validationErrorMessage.isPresent()) { sendMessage.to(sender.getId(), validationErrorMessage.get()); sendMessage.to(sender.getId(), commandContainer.getCommandOptions().getUsage()); } else { List<String> argumentCollection = Arrays.asList(arguments).subList(1, arguments.length); command.execute( new StaticCommandExecution(sender, new ValidatingArgumentSet( new ListArgumentSet(argumentCollection)), arguments[0])); } }  }
CommandExecutor { public void execute(CommandRegistration commandContainer, Sender sender, String[] arguments) { Command command = commandContainer.getCommand(); Optional<Message> validationErrorMessage = validator.validate(commandContainer.getCommandOptions(), arguments, sender); if (validationErrorMessage.isPresent()) { sendMessage.to(sender.getId(), validationErrorMessage.get()); sendMessage.to(sender.getId(), commandContainer.getCommandOptions().getUsage()); } else { List<String> argumentCollection = Arrays.asList(arguments).subList(1, arguments.length); command.execute( new StaticCommandExecution(sender, new ValidatingArgumentSet( new ListArgumentSet(argumentCollection)), arguments[0])); } }  void execute(CommandRegistration commandContainer, Sender sender, String[] arguments); }
CommandExecutor { public void execute(CommandRegistration commandContainer, Sender sender, String[] arguments) { Command command = commandContainer.getCommand(); Optional<Message> validationErrorMessage = validator.validate(commandContainer.getCommandOptions(), arguments, sender); if (validationErrorMessage.isPresent()) { sendMessage.to(sender.getId(), validationErrorMessage.get()); sendMessage.to(sender.getId(), commandContainer.getCommandOptions().getUsage()); } else { List<String> argumentCollection = Arrays.asList(arguments).subList(1, arguments.length); command.execute( new StaticCommandExecution(sender, new ValidatingArgumentSet( new ListArgumentSet(argumentCollection)), arguments[0])); } }  void execute(CommandRegistration commandContainer, Sender sender, String[] arguments);  }