예제 #1
0
  public PircTestRunner(Configuration.Builder config) throws IOException, IrcException {
    ACTIVE_INSTANCE_COUNT++;

    InetAddress address = InetAddress.getByName("127.1.1.1");
    Socket socket = mock(Socket.class);
    when(socket.isConnected()).thenReturn(true);
    when(socket.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[0]));
    when(socket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
    SocketFactory socketFactory = mock(SocketFactory.class);
    when(socketFactory.createSocket(eq(address), anyInt(), eq((InetAddress) null), eq(0)))
        .thenReturn(socket);
    config.setSocketFactory(socketFactory);

    config.setListenerManager(
        new GenericListenerManager() {
          final Logger log = LoggerFactory.getLogger(getClass());

          @Override
          public void onEvent(Event event) {
            log.debug("Dispatched event " + event);
            eventQueue.addLast(event);
          }
        });

    in = new FakeReader();

    bot = new CapturedPircBotX(config.buildConfiguration());
    bot.startBot();
  }
예제 #2
0
  public PircTestRunner assertBotHello() {
    assertEventClass(SocketConnectEvent.class);
    assertBotOut("NICK TestBot");
    assertBotOut("USER PircBotX 8 * :" + bot.getConfiguration().getVersion());

    checkAllEmpty();

    return this;
  }
예제 #3
0
  @Override
  public void close() {
    checkAllEmpty();

    bot.shutdownEnabled = true;
    botIn("ERROR: test is over");
    assertTrue(bot.closeCalled, "Shutdown wasn't called");
    ACTIVE_INSTANCE_COUNT--;
  }
예제 #4
0
  public PircTestRunner botIn(@NonNull String line) {
    checkInputEmpty();
    checkOutputEmpty();
    checkEventsEmpty();

    in.nextLine =
        StringUtils.replaceEach(
            line,
            new String[] {
              "%server", "%usersource", "%userother", "%userbot", "%nickbot",
            },
            new String[] {
              "irc.someserver.net",
              USER_SOURCE_HOSTMASK,
              USER_OTHER_HOSTMASK,
              USER_BOT_HOSTMASK,
              BOT_NICK,
            });
    assertTrue(bot.processNextLine(), "Bot was stopped");

    return this;
  }