TopicManagerImpl implements TopicManager { boolean unregisterTopicSessions(String topic, Collection<Session> sessions) { boolean unregister = false; if (sessions != null && !sessions.isEmpty()) { Collection<Session> all = map.get(topic); if(all != null) { unregister = all.removeAll(sessions); if (all.isEmpty()) { map.remove(topic); } } } return unregister; }  @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 testUnregisterTopicSessions() throws IllegalAccessException { System.out.println("unregisterTopicSessions"); Collection<Session> sessions = new ArrayList<>(); Session session = mock(Session.class); when(session.isOpen()).thenReturn(true); int result = instance.registerTopicSession(TOPIC1, session); assertThat(result).isEqualTo(1); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(1); sessions.add(session); Session session1 = mock(Session.class); when(session1.isOpen()).thenReturn(true); result = instance.registerTopicSession(TOPIC1, session1); assertThat(result).isEqualTo(2); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(2); sessions.add(session1); boolean res = instance.unregisterTopicSessions(TOPIC1, sessions); assertThat(res).isTrue(); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(0); res = instance.unregisterTopicSessions(TOPIC1, null); assertThat(res).isFalse(); res = instance.unregisterTopicSessions(TOPIC1, Collections.EMPTY_LIST); assertThat(res).isFalse(); }