Esempio n. 1
0
  @Test
  public void testCommand() throws CommandException {
    CommandManager cm = new CommandManager();
    CommandSource testSource = new TestCommandSource(cm);
    Command cmd =
        cm.getCommand("test1")
            .addAlias("t1")
            .setPermission("test.1")
            .setExecutor(
                new Executor() {
                  @Override
                  public void execute(CommandSource source, Command command, CommandArguments args)
                      throws CommandException {
                    args.popString("testArg1");
                    args.popString("testArg2", "Not specified");
                    args.assertCompletelyParsed();
                  }
                });

    // execute with success
    cmd.process(testSource, "foo");
    cmd.process(testSource, "foo", "bar");

    // execute with failure
    thrown.expect(CommandException.class);
    cmd.process(testSource, "foo", "bar", "baz");
    cmd.process(testSource);
  }
Esempio n. 2
0
    @Override
    public void processCommand(String command, String... args) {
      Command cmd = cm.getCommand(command, false);
      if (cmd == null) {
        sendMessage("Unknown command: '" + command + "'.");
        return;
      }

      try {
        cmd.process(this, args);
      } catch (CommandException e) {
        throw new RuntimeException(e);
      }
    }
Esempio n. 3
0
  @Test
  public void testProcessExitCommand_thowsExitException() {
    // given
    Command command = new Exit(view);

    // when
    try {
      command.process("exit");
      fail("Expected ExitException");
    } catch (ExitException e) {
      // do nothing
    }

    // then
    Mockito.verify(view).write("До скорой встречи!");
  }