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(); }