TopicManagerImpl implements TopicManager { @Override public int unregisterTopicSession(String topic, Session session) { if (isInconsistenceContext(topic, session)) { return 0; } logger.debug("'{}' unsubscribe to '{}'", session.getId(), topic); if (Constants.Topic.ALL.equals(topic)) { for (Map.Entry<String, Collection<Session>> entry : map.entrySet()) { Collection<Session> sessions = entry.getValue(); removeSessionToSessions(session, sessions); if (sessions.isEmpty()) { map.remove(entry.getKey()); } } } else { Collection<Session> sessions = map.get(topic); removeSessionToSessions(session, sessions); if (sessions==null || sessions.isEmpty()) { map.remove(topic); } } return getNumberSubscribers(topic); }  @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 testUnregisterTopicSession() throws IllegalAccessException { System.out.println("unregisterTopicSession"); Session session = mock(Session.class); when(session.isOpen()).thenReturn(true); int result = instance.unregisterTopicSession(null, session); assertThat(result).isEqualTo(0); result = instance.unregisterTopicSession("", session); assertThat(result).isEqualTo(0); result = instance.registerTopicSession(TOPIC1, session); assertThat(result).isEqualTo(1); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(1); result = instance.unregisterTopicSession(TOPIC1, session); assertThat(result).isEqualTo(0); assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(0); }