HandlerCaller implements EventVisitor { @Override public void visit(CloseEvent event) { IoSession session = event.getSession(); try { session.getService().getIoHandler().sessionClosed(session); } catch (Exception e) { session.getService().getIoHandler().exceptionCaught(session, e); } }  @Override void visit(CloseEvent event); @Override void visit(IdleEvent event); @Override void visit(OpenEvent event); @Override void visit(ReceiveEvent event); @Override void visit(SentEvent event); @Override void visit(HandshakeStartedEvent event); @Override void visit(HandshakeCompletedEvent event); @Override void visit(SecureClosedEvent event);  }
@Test public void call_open() { OpenEvent event = mock(OpenEvent.class); when(event.getSession()).thenReturn(session); caller.visit(event); verify(event).getSession(); verify(session).getService(); verify(service).getIoHandler(); verify(handler).sessionOpened(session); verifyNoMoreInteractions(session, event, handler); }
@Test public void call_close() { CloseEvent event = mock(CloseEvent.class); when(event.getSession()).thenReturn(session); caller.visit(event); verify(event).getSession(); verify(session).getService(); verify(service).getIoHandler(); verify(handler).sessionClosed(session); verifyNoMoreInteractions(session, event, handler); }
@Test public void call_idle() { IdleEvent event = mock(IdleEvent.class); IdleStatus status = IdleStatus.READ_IDLE; when(event.getIdleStatus()).thenReturn(status); when(event.getSession()).thenReturn(session); caller.visit(event); verify(event).getSession(); verify(event).getIdleStatus(); verify(session).getService(); verify(service).getIoHandler(); verify(handler).sessionIdle(session, status); verifyNoMoreInteractions(session, event, handler); }
@Test public void call_receive() { ReceiveEvent event = mock(ReceiveEvent.class); Object msg = mock(Object.class); when(event.getMessage()).thenReturn(msg); when(event.getSession()).thenReturn(session); caller.visit(event); verify(event).getSession(); verify(event).getMessage(); verify(session).getService(); verify(service).getIoHandler(); verify(handler).messageReceived(session, msg); verifyNoMoreInteractions(session, event, handler); }
@Test public void call_msg_sent() { SentEvent event = mock(SentEvent.class); Object msg = mock(Object.class); when(event.getMessage()).thenReturn(msg); when(event.getSession()).thenReturn(session); caller.visit(event); verify(event).getSession(); verify(event).getMessage(); verify(session).getService(); verify(service).getIoHandler(); verify(handler).messageSent(session, msg); verifyNoMoreInteractions(session, event, handler); }