TopicsMessagesObservers { public int sendMessageToUserTopic(@Observes @MessageEvent(userScope = true) MessageToClient msg) { HttpSession httpSession = ocelotContext.getHttpSession(); if(httpSession!=null) { String httpid = httpSession.getId(); Collection<Session> userSessions = sessionManager.getUserSessions(httpid); return topicsMessagesBroadcaster.sendMessageToTopic(userSessions, msg, getPayload(msg)); } return 0; }  void sendObjectToTopic(@Observes @JsTopicEvent("") Object payload, EventMetadata metadata); int sendMessageToTopic(@Observes @MessageEvent MessageToClient msg); int sendMessageToUserTopic(@Observes @MessageEvent(userScope = true) MessageToClient msg);  }
@Test public void sendMessageToUserTopicTest() { System.out.println("sendMessageToUserTopic"); HttpSession httpSession = mock(HttpSession.class); Collection userSessions = mock(Collection.class); MessageToClient mtc = mock(MessageToClient.class); when(httpSession.getId()).thenReturn("HTTPID"); when(ocelotContext.getHttpSession()).thenReturn(null, httpSession); when(sessionManager.getUserSessions(eq("HTTPID"))).thenReturn(userSessions); doReturn("PAYLOAD").when(instance).getPayload(eq(mtc)); when(topicsMessagesBroadcaster.sendMessageToTopic(eq(userSessions), eq(mtc), eq("PAYLOAD"))).thenReturn(5); int result = instance.sendMessageToUserTopic(mtc); assertThat(result).isEqualTo(0); result = instance.sendMessageToUserTopic(mtc); assertThat(result).isEqualTo(5); }