@Test
  public void infoCommandTest() {
    System.out.println("--INFO-------------------------------------------");

    dropAll();
    serverInit();
    userInit();
    operatorInit();
    serviceInit();

    IrcCommandParser icp = new IrcCommandParser();

    String reply;
    String prefix;
    String ircCommand;
    String response;

    icp.setRequestor(User.create());
    ((User) icp.getRequestor()).setIrcServer(Globals.thisIrcServer.get());
    icp.getRequestor().setConnection(Connection.create());

    ircCommand = "INFO";
    icp.setParsingString(ircCommand);
    prefix = Globals.thisIrcServer.get().getHostname();
    response = "451" + " " + "" + " " + ":" + "You have not registered";
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("Not registered reply", reply, ":" + prefix + " " + response);
    // String infoFilename = Globals.infoFilename.get();

    icp.setRequestor(requestor[0]);

    //           371    RPL_INFO ":<string>"
    //           374    RPL_ENDOFINFO ":End of INFO list"

    ircCommand = "INFO";
    String serverMask = "";
    icp.setParsingString(ircCommand + " " + serverMask);
    prefix = Globals.thisIrcServer.get().getHostname();
    icp.ircParse();

    prefix = Globals.thisIrcServer.get().getHostname();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    response = "371" + " " + requestor[0].getNickname() + " " + ":" + ".*";
    while (reply.matches(":" + prefix + " " + response)) {
      assertTrue("RPL_INFO", reply.matches(":" + prefix + " " + response));
      reply = icp.getRequestor().getOutputQueue().poll().getReport();
    }
    response = "374" + " " + requestor[0].getNickname() + " " + ":" + "End of INFO list";
    assertEquals("RPL_ENDOFINFO", reply, ":" + prefix + " " + response);

    ircCommand = "INFO";
    serverMask = "*.irc.example.com";
    icp.setParsingString(ircCommand + " " + serverMask);
    prefix = Globals.thisIrcServer.get().getHostname();
    // 402    ERR_NOSUCHSERVER "<server name> :No such server"
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    response =
        "402" + " " + requestor[0].getNickname() + " " + serverMask + " " + ":" + "No such server";
    assertEquals("ERR_NOSUCHSERVER", reply, ":" + prefix + " " + response);

    System.out.println("**INFO***************************************OK**");
  }
  @Test
  public void kickCommandTest() {
    System.out.println("--KICK-------------------------------------------");
    String reply;
    String prefix = Globals.thisIrcServer.get().getHostname();
    String ircCommand;
    String response;
    String responseCode;

    int i;

    dropAll();
    serverInit();
    serviceInit();
    userInit();
    operatorInit();

    IrcCommandParser icp = new IrcCommandParser();

    icp.setRequestor(User.create());
    ((User) icp.getRequestor()).setIrcServer(Globals.thisIrcServer.get());
    icp.getRequestor().setConnection(Connection.create());

    // 451    ERR_NOTREGISTERED ":You have not registered"

    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[0]);
    response = "451" + " " + "" + " " + ":" + "You have not registered";
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("Not registered", ":" + prefix + " " + response, reply);

    icp.setRequestor(db.getUser(userNickname[0]));

    ircCommand = "JOIN";
    icp.setParsingString(ircCommand + " " + channelName[0]);
    icp.ircParse();
    icp.getRequestor().getOutputQueue().clear();

    for (IrcTalker ircTalker : requestor) {
      if (ircTalker.getOutputQueue() != null) ircTalker.getOutputQueue().clear();
    }

    ircCommand = "OPER";
    icp.setParsingString(ircCommand + " " + "operatorname1" + " " + "operatorpassword1");
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();

    // 461    ERR_NEEDMOREPARAMS "<command> :Not enough parameters"
    ircCommand = "KICK";
    icp.setParsingString(ircCommand);
    icp.ircParse();
    responseCode = "461";
    response =
        responseCode
            + " "
            + userNickname[0]
            + " "
            + ircCommand
            + " "
            + ":"
            + "Not enough parameters";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("ERR_NEEDMOREPARAMS", ":" + prefix + " " + response, reply);

    // 461    ERR_NEEDMOREPARAMS "<command> :Not enough parameters"
    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0]);
    icp.ircParse();
    responseCode = "461";
    response =
        responseCode
            + " "
            + userNickname[0]
            + " "
            + ircCommand
            + " "
            + ":"
            + "Not enough parameters";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("ERR_NEEDMOREPARAMS", ":" + prefix + " " + response, reply);

    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[1] + " " + userNickname[1]);
    icp.ircParse();
    // 403    ERR_NOSUCHCHANNEL "<channel name> :No such channel"
    responseCode = "403";
    response =
        responseCode + " " + userNickname[0] + " " + channelName[1] + " " + ":" + "No such channel";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("check ERR_NOSUCHCHANNEL", ":" + prefix + " " + response, reply);

    ircCommand = "KICK";
    String name = "nOsUch";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + name);
    icp.ircParse();
    // 401    ERR_NOSUCHNICK "<nick> :No such nick/channel"
    responseCode = "401";
    response =
        responseCode + " " + userNickname[0] + " " + name + " " + ":" + "No such nick/channel";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("check ERR_NOSUCHNICK", ":" + prefix + " " + response, reply);

    ircCommand = "MODE";
    icp.setParsingString(ircCommand + " " + userNickname[0] + " " + "-o");
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();

    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[1]);
    icp.ircParse();
    // 441    ERR_USERNOTINCHANNEL "<nick> <channel> :They aren't on that channel"
    responseCode = "441";
    response =
        responseCode
            + " "
            + userNickname[0]
            + " "
            + userNickname[1]
            + " "
            + channelName[0]
            + " "
            + ":"
            + "They aren't on that channel";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("check ERR_USERNOTINCHANNEL", ":" + prefix + " " + response, reply);

    for (i = 1; i < requestor.length; i++) {
      icp.setRequestor(requestor[i]);
      ircCommand = "JOIN";
      icp.setParsingString(ircCommand + " " + channelName[0]);
      icp.ircParse();
    }

    icp.setRequestor(db.getUser(userNickname[1]));
    ircCommand = "JOIN";
    icp.setParsingString(ircCommand + " " + channelName[1]);
    icp.ircParse();

    for (IrcTalker ircTalker : requestor) {
      if (ircTalker.getOutputQueue() != null) ircTalker.getOutputQueue().clear();
    }

    icp.setRequestor(db.getUser(userNickname[0]));
    // 442    ERR_NOTONCHANNEL "<channel> :You're not on that channel"
    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[1] + " " + userNickname[1]);
    icp.ircParse();
    responseCode = "442";
    response =
        responseCode
            + " "
            + userNickname[0]
            + " "
            + channelName[1]
            + " "
            + ":"
            + "You're not on that channel";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("ERR_NOTONCHANNEL", ":" + prefix + " " + response, reply);

    icp.setRequestor(db.getUser(userNickname[1]));
    ircCommand = "PART";
    icp.setParsingString(ircCommand + " " + channelName[1]);
    icp.ircParse();

    for (IrcTalker ircTalker : requestor) {
      if (ircTalker.getOutputQueue() != null) ircTalker.getOutputQueue().clear();
    }

    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[1]);
    icp.ircParse();
    // 482    ERR_CHANOPRIVSNEEDED "<channel> :You're not channel operator"
    responseCode = "482";
    response =
        responseCode
            + " "
            + userNickname[1]
            + " "
            + channelName[0]
            + " "
            + ":"
            + "You're not channel operator";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "check ERR_CHANOPRIVSNEEDED for selfkicking", ":" + prefix + " " + response, reply);

    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[2]);
    icp.ircParse();
    // 482    ERR_CHANOPRIVSNEEDED "<channel> :You're not channel operator"
    responseCode = "482";
    response =
        responseCode
            + " "
            + userNickname[1]
            + " "
            + channelName[0]
            + " "
            + ":"
            + "You're not channel operator";
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("check ERR_CHANOPRIVSNEEDED", ":" + prefix + " " + response, reply);

    icp.setRequestor(db.getUser(userNickname[0]));
    ircCommand = "KICK";
    icp.setParsingString(
        ircCommand + " " + channelName[0] + " " + userNickname[1] + "," + userNickname[2]);
    icp.ircParse();
    response = ircCommand + " " + channelName[0] + " " + userNickname[1];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to first user (about first kicked).", ":" + userNickname[0] + " " + response, reply);

    icp.setRequestor(db.getUser(userNickname[1]));
    response = ircCommand + " " + channelName[0] + " " + userNickname[1];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to second user (about first kicked).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[2]));
    response = ircCommand + " " + channelName[0] + " " + userNickname[1];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to third user (about first kicked).", ":" + userNickname[0] + " " + response, reply);

    icp.setRequestor(db.getUser(userNickname[0]));
    response = ircCommand + " " + channelName[0] + " " + userNickname[2];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to first user (about second kicked).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[2]));
    response = ircCommand + " " + channelName[0] + " " + userNickname[2];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to second user (about second kicked).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[0]));
    ircCommand = "JOIN";
    icp.setParsingString(ircCommand + " " + channelName[1]);
    icp.ircParse();

    icp.setRequestor(db.getUser(userNickname[1]));
    ircCommand = "JOIN";
    icp.setParsingString(ircCommand + " " + channelName[0]);
    icp.ircParse();

    icp.setRequestor(db.getUser(userNickname[2]));
    ircCommand = "JOIN";
    icp.setParsingString(ircCommand + " " + channelName[1]);
    icp.ircParse();

    for (IrcTalker ircTalker : requestor) {
      if (ircTalker.getOutputQueue() != null) ircTalker.getOutputQueue().clear();
    }

    icp.setRequestor(db.getUser(userNickname[0]));

    ircCommand = "KICK";
    icp.setParsingString(
        ircCommand
            + " "
            + channelName[0]
            + ","
            + channelName[1]
            + " "
            + userNickname[1]
            + ","
            + userNickname[2]);
    icp.ircParse();
    response = ircCommand + " " + channelName[0] + " " + userNickname[1];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to first user (about first kicked from first channel).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[1]));
    response = ircCommand + " " + channelName[0] + " " + userNickname[1];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to second user (about first kicked from first channel).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[0]));
    response = ircCommand + " " + channelName[1] + " " + userNickname[2];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to first user (about second kicked from second channel).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[2]));
    response = ircCommand + " " + channelName[1] + " " + userNickname[2];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "Reply to second user (about second kicked from second channel).",
        ":" + userNickname[0] + " " + response,
        reply);

    icp.setRequestor(db.getUser(userNickname[0]));
    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[0]);
    icp.ircParse();
    response = ircCommand + " " + channelName[0] + " " + userNickname[0];
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals(
        "for chopers selfkicking is allowed", ":" + userNickname[0] + " " + response, reply);

    icp.setRequestor(db.getService(serviceNickname[0]));
    ircCommand = "KICK";
    icp.setParsingString(ircCommand + " " + channelName[0] + " " + userNickname[0]);
    response = "421" + " " + service[0].getNickname() + " " + ircCommand + " " + ":Unknown command";
    icp.ircParse();
    reply = icp.getRequestor().getOutputQueue().poll().getReport();
    assertEquals("Unknown command", ":" + prefix + " " + response, reply);

    System.out.println("**KICK***************************************OK**");
  }