@Test
  public void testSend() throws Exception {
    WaitForAsyncUtils.async(
        () -> {
          handleAllocationRequest();
          handleCreatePermissionRequest();
          handleChannelBindRequest();

          return null;
        });

    instance.connect().get(5, TimeUnit.SECONDS);

    InetSocketAddress remotePeerAddress = new InetSocketAddress("93.184.216.34", 1234);

    CreatePermissionMessage createPermissionMessage = new CreatePermissionMessage();
    createPermissionMessage.setAddress(remotePeerAddress);

    verify(lobbyServerAccessor)
        .addOnMessageListener(
            eq(CreatePermissionMessage.class), createPermissionListenerCaptor.capture());
    createPermissionListenerCaptor.getValue().accept(createPermissionMessage);

    byte[] bytes = new byte[1024];
    DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
    datagramPacket.setSocketAddress(remotePeerAddress);

    instance.send(datagramPacket);
  }
  @Test
  public void testGetRelayAddress() throws Exception {
    assertThat(instance.getRelayAddress(), nullValue());

    WaitForAsyncUtils.async(
        () -> {
          handleAllocationRequest();
          handleCreatePermissionRequest();
          handleChannelBindRequest();

          return null;
        });

    instance.connect().get(5, TimeUnit.SECONDS);

    InetSocketAddress relayAddress = instance.getRelayAddress();
    assertThat(
        relayAddress.getAddress().getHostAddress(),
        is(turnServerSocket.getLocalAddress().getHostAddress()));
    assertThat(relayAddress.getPort(), is(2222));
  }
  @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();
  }
  @Test
  public void testConnect() throws Exception {
    WaitForAsyncUtils.async(
        () -> {
          handleAllocationRequest();
          return null;
        });

    InetSocketAddress socketAddress = (InetSocketAddress) instance.connect().get();
    assertThat(
        socketAddress.getAddress().getHostAddress(),
        is(turnServerSocket.getLocalAddress().getHostAddress()));
    assertThat(socketAddress.getPort(), is(2222));

    verify(scheduledExecutorService).scheduleWithFixedDelay(any(), anyLong(), anyLong(), any());
  }
 @Test
 public void testClose() throws Exception {
   instance.close();
 }