RSMonitorDecorator implements RSMessageToClientService { @Override public MessageToClient createMessageToClient(MessageFromClient message, HttpSession session) { boolean monitor = isMonitored(session); logger.debug("Monitor is enabled : {}", monitor); long t0 = getT0(monitor); MessageToClient mtc = messageToClientService.createMessageToClient(message, session); setTiming(monitor, t0, mtc); return mtc; }  @Override MessageToClient createMessageToClient(MessageFromClient message, HttpSession session);  }
@Test public void testCreateMessageToClientMonitor() { System.out.println("createMessageToClient"); MessageFromClient message = mock(MessageFromClient.class); HttpSession session = mock(HttpSession.class); Options options = new Options(); options.setMonitor(true); when(session.getAttribute(Constants.Options.OPTIONS)).thenReturn(options); MessageToClient result = instance.createMessageToClient(message, session); assertThat(result.getTime()).isGreaterThanOrEqualTo(WAIT); }
@Test public void testCreateMessageToClientNoMonitor() { System.out.println("createMessageToClient"); MessageFromClient message = mock(MessageFromClient.class); HttpSession session = mock(HttpSession.class); Map<String, Object> map = new HashMap<>(); Options options = new Options(); options.setMonitor(false); when(session.getAttribute(Constants.Options.OPTIONS)).thenReturn(options); MessageToClient result = instance.createMessageToClient(message, session); assertThat(result.getTime()).isZero(); }
@Test public void testCreateMessageToClientFail() { System.out.println("createMessageToClient"); MessageToClient result = instance.createMessageToClient(null, null); assertThat(result.getTime()).isZero(); }