GameController { @RequestMapping(value = "joinSession", method = RequestMethod.POST) public void joinSession( @RequestParam(name = "sessionId") final Long sessionId, @RequestParam(name = "userName") final String userName ) { if (sessionId < SESSION_SEQ_START_VALUE || !sessionManager.isSessionActive(sessionId)) { throw new IllegalArgumentException("session not found"); } else if (containsIgnoreCase(sessionManager.getSessionUsers(sessionId), userName)) { throw new IllegalArgumentException("user exists"); } else { sessionManager.registerUser(userName, sessionId); logger.info(userName + " has joined session " + sessionId); messagingUtils.burstUsersMessages(sessionId); } } @Autowired  GameController(SessionManager sessionManager, MessagingUtils messagingUtils); @RequestMapping(value = "joinSession", method = RequestMethod.POST) void joinSession(
            @RequestParam(name = "sessionId") final Long sessionId,
            @RequestParam(name = "userName") final String userName
    ); @RequestMapping(value = "createSession", method = RequestMethod.POST) long createSession(
            @RequestParam(name = "userName") final String userName
    ); @RequestMapping(value = "logout", method = RequestMethod.POST) void leaveSession(
            @RequestParam(name = "userName") final String userName,
            @RequestParam(name = "sessionId") final Long sessionId
    ); @RequestMapping(value = "refresh", method = RequestMethod.GET) void refresh(
            @RequestParam(name = "sessionId") final Long sessionId
    ); @RequestMapping(value = "sessionUsers", method = RequestMethod.GET) List<String> getSessionUsers(
            @RequestParam(name = "sessionId") final Long sessionId
    ); @RequestMapping(value = "sessions", method = RequestMethod.GET) @ResponseBody Map<Long, List<String>> getSessions(); @RequestMapping(value = "reset", method = RequestMethod.POST) void reset(
            @RequestParam(name = "sessionId") final Long sessionId,
            @RequestParam(name = "userName") final String userName
    );  }
@Test public void testJoinSession() throws Exception { when(sessionManager.isSessionActive(SESSION_ID)).thenReturn(true); gameController.joinSession(SESSION_ID, USER_NAME); inOrder.verify(sessionManager, times(1)).registerUser(USER_NAME, SESSION_ID); inOrder.verify(messagingUtils).burstUsersMessages(SESSION_ID); inOrder.verifyNoMoreInteractions(); }
@Test(expected = IllegalArgumentException.class) public void testJoinInactiveSession() throws Exception { when(sessionManager.isSessionActive(SESSION_ID)).thenReturn(false); gameController.joinSession(SESSION_ID, USER_NAME); }
@Test(expected = IllegalArgumentException.class) public void testJoinInvalidSession() throws Exception { gameController.joinSession(SessionManager.SESSION_SEQ_START_VALUE - 1, USER_NAME); }