WSController implements IWSController { @Override public void handleClosedConnexion(Session session, CloseReason closeReason) { logger.debug("Close connexion for session '{}' : '{}'", session.getId(), closeReason); if (session.isOpen()) { try { session.close(); } catch (IllegalStateException | IOException ex) { } } userContextFactory.destroyUserContext(session.getId()); topicManager.removeSessionToTopics(session); }  @Override void handleOpenConnexion(Session session, EndpointConfig config); @Override void onError(Session session, Throwable t); @Override void handleClosedConnexion(Session session, CloseReason closeReason); @Override void receiveCommandMessage(Session client, String json);  }
@Test public void testHandleClosedConnection() throws IOException { System.out.println("handleClosedConnection"); Session session = mock(Session.class); when(session.getId()).thenReturn(UUID.randomUUID().toString()); when(session.isOpen()).thenReturn(true); CloseReason closeReason = mock(CloseReason.class); when(closeReason.getCloseCode()).thenReturn(CloseReason.CloseCodes.TOO_BIG); instance.handleClosedConnexion(session, closeReason); doThrow(IOException.class).when(session).close(); instance.handleClosedConnexion(session, closeReason); doThrow(IllegalStateException.class).when(session).close(); instance.handleClosedConnexion(session, closeReason); when(session.isOpen()).thenReturn(false); instance.handleClosedConnexion(session, closeReason); }