TopicManagerImpl implements TopicManager { @Override public Collection<String> removeSessionsToTopic(Collection<Session> sessions) { if (sessions != null && !sessions.isEmpty()) { Collection<String> topicUpdated = new ArrayList<>(); for (String topic : map.keySet()) { if(unregisterTopicSessions(topic, sessions)) { topicUpdated.add(topic); sendSubscriptionEvent(Constants.Topic.SUBSCRIBERS + Constants.Topic.COLON + topic, getNumberSubscribers(topic)); } } return topicUpdated; } return Collections.EMPTY_LIST; }  @Override Map<String, Collection<Session>> getSessionsByTopic(); @Override int registerTopicSession(String topic, Session session); @Override int unregisterTopicSession(String topic, Session session); @Override Collection<String> removeSessionsToTopic(Collection<Session> sessions); @Override Collection<String> removeSessionToTopics(Session session); @Override Collection<Session> getSessionsForTopic(String topic); @Override int getNumberSubscribers(String topic);  }
@Test public void testRemoveSessionsToTopic() throws IllegalAccessException { System.out.println("removeSessionsToTopic"); Collection<Session> sessions = new ArrayList<>(); Session session = mock(Session.class); sessions.add(session); when(session.isOpen()).thenReturn(true); int result = instance.registerTopicSession(TOPIC1, session); assertThat(result).isEqualTo(1); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(1); Session session1 = mock(Session.class); sessions.add(session1); when(session1.isOpen()).thenReturn(true); result = instance.registerTopicSession(TOPIC2, session1); assertThat(result).isEqualTo(1); assertThat(instance.getNumberSubscribers(TOPIC2)).isEqualTo(1); instance.removeSessionsToTopic(sessions); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(0); assertThat(instance.getNumberSubscribers(TOPIC2)).isEqualTo(0); instance.removeSessionsToTopic(null); instance.removeSessionsToTopic(Collections.EMPTY_LIST); }