@Test(dataProvider = "onCommandLongTests") public void executeOnCommandLongTest( String cmdMessage, OnCommandLong command, String[][] expectedArgs) throws Exception { // Build the CommandEvent CommandEvent event = new CommandEvent( command, new MessageEvent(bot, null, null, cmdMessage), null, null, cmdMessage, "?testCommand", hook.getArgs(cmdMessage)); // Execute and verify values String returned = hook.executeOnCommandLong(event); assertEquals(returned, "Success", "onCommandLong doesn't return expected value"); log.debug("Current command: " + command.getName()); logMultiArray(expectedArgs, "Expected args"); logMultiArray(command.getArgs(), "Given args"); assertTrue( Arrays.deepEquals(command.getArgs(), expectedArgs), "Command test " + command.getName() + " args don't equal"); }
/** 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); }