@Before public void setUp() throws Exception { DatagramSocket serverSocket = startFakeTurnServer(); instance = new TurnClientImpl(); instance.scheduledExecutorService = scheduledExecutorService; instance.lobbyServerAccessor = lobbyServerAccessor; instance.turnHost = serverSocket.getLocalAddress().getHostAddress(); instance.turnPort = serverSocket.getLocalPort(); eventsReceivedByTurnServer = new LinkedBlockingQueue<>(); Mockito.doAnswer( invocation -> { invocation.getArgumentAt(0, Runnable.class).run(); return null; }) .when(scheduledExecutorService) .execute(any()); instance.postConstruct(); }