CallServiceManager implements CallService { @Override public boolean sendMessageToClient(MessageFromClient message, Session client) { MessageToClient mtc = messageToClientService.createMessageToClient(message, client); if (mtc != null) { client.getAsyncRemote().sendObject(mtc); return true; } return false; }  @Override boolean sendMessageToClient(MessageFromClient message, Session client);  }
@Test public void testSendMessageToClient() { System.out.println("sendMessageToClient"); Session client = mock(Session.class); MessageToClient mtc = mock(MessageToClient.class); RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class); when(client.getAsyncRemote()).thenReturn(async); when(messageToClientService.createMessageToClient(any(MessageFromClient.class), any(Session.class))).thenReturn(mtc).thenReturn(null); boolean result = instance.sendMessageToClient(new MessageFromClient(), client); assertThat(result).isTrue(); result = instance.sendMessageToClient(new MessageFromClient(), client); assertThat(result).isFalse(); ArgumentCaptor<MessageToClient> captureMsg = ArgumentCaptor.forClass(MessageToClient.class); verify(async).sendObject(captureMsg.capture()); assertThat(captureMsg.getValue()).isEqualTo(mtc); }