public void closeConnection(final AuthenticatedDevice authenticatedDevice) {
    // Channels will actually get removed from the list/map by their closeFuture listeners
    remoteChannelsByAuthenticatedDevice.getOrDefault(authenticatedDevice, Collections.emptyList()).forEach(channel ->
        channel.writeAndFlush(new CloseWebSocketFrame(ApplicationWebSocketCloseReason.REAUTHENTICATION_REQUIRED
                .toWebSocketCloseStatus("Reauthentication required")))
            .addListener(ChannelFutureListener.CLOSE_ON_FAILURE));
  }
@Test
  void closeConnection() throws InterruptedException {
    final AuthenticatedDevice authenticatedDevice = new AuthenticatedDevice(UUID.randomUUID(), Device.PRIMARY_ID);

    clientConnectionManager.handleConnectionEstablished(localChannel, remoteChannel, Optional.of(authenticatedDevice));

    assertTrue(remoteChannel.isOpen());

    assertEquals(remoteChannel, clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
    assertEquals(List.of(remoteChannel),
        clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));

    remoteChannel.close().await();

    assertNull(clientConnectionManager.getRemoteChannelByLocalAddress(localChannel.localAddress()));
    assertNull(clientConnectionManager.getRemoteChannelsByAuthenticatedDevice(authenticatedDevice));
  }