### Question:
WebSocketProxyServerHandler extends AbstractWebSocketHandler implements RoutedServicesUser { @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { log.debug("afterConnectionClosed(session={},status={})", session, status); try { session.close(status); WebSocketRoutedSession webSocketRoutedSession = getRoutedSession(session); if (webSocketRoutedSession != null) { webSocketRoutedSession.close(status); } routedSessions.remove(session.getId()); } catch (NullPointerException | IOException e) { log.debug("Error closing WebSocket connection: {}", e.getMessage(), e); } } @Autowired  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider jettySslContextFactoryProvider);  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider sslContextFactoryProvider,
                                       Map<String, WebSocketRoutedSession> routedSessions, WebSocketRoutedSessionFactory webSocketRoutedSessionFactory); void addRoutedServices(String serviceId, RoutedServices routedServices); Map<String, WebSocketRoutedSession> getRoutedSessions(); @Override void afterConnectionEstablished(WebSocketSession webSocketSession); @Override void afterConnectionClosed(WebSocketSession session, CloseStatus status); @Override void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage);  }### Answer:
@Test void givenValidSession_whenTheConnectionIsClosed_thenTheSessionIsClosedAndRemovedFromRepository() throws Exception { CloseStatus normalClose = CloseStatus.NORMAL; WebSocketSession establishedSession = mock(WebSocketSession.class); String validSessionId = "123"; when(establishedSession.getId()).thenReturn(validSessionId); routedSessions.put(validSessionId, mock(WebSocketRoutedSession.class)); underTest.afterConnectionClosed(establishedSession, normalClose); verify(establishedSession).close(normalClose); assertThat(routedSessions.entrySet(), hasSize(0)); }