Esempio n. 1
0
  /** Instead of only testing onCommandLong, test feeding into onMessage */
  @Test(dataProvider = "onCommandLongTests")
  public void executeTest(String cmdMessage, OnCommandLong command, String[][] expectedArgs)
      throws Exception {
    // Remove the prefix
    cmdMessage = cmdMessage.substring(1);

    // Build the messageEvent
    final StringBuilder response = new StringBuilder();
    MessageEvent messageEvent =
        new MessageEvent(bot, channel, null, cmdMessage) {
          @Override
          public void respond(String commandResponse) {
            if (commandResponse != null) response.append(commandResponse);
          }
        };

    // Add our test listener
    controller.getHookManager().addHook(command);

    // Feed into onMessage
    log.trace("Sending message " + cmdMessage);
    hook.execute(messageEvent, channel, user, cmdMessage);

    // Verify the results
    assertEquals(
        response.toString(),
        "Success",
        "onCommandLong in test " + command.getName() + " doesn't return expected value");
    assertTrue(
        Arrays.deepEquals(command.getArgs(), expectedArgs),
        "Command test " + command.getName() + " args don't equal");

    // Remove it to cleanup
    controller.getHookManager().removeHook(command);
  }