VoteController { @RequestMapping(value = "vote", method = RequestMethod.POST) public void vote( @RequestParam(name = "sessionId") final Long sessionId, @RequestParam(name = "userName") final String userName, @RequestParam(name = "estimateValue") final String estimateValue ) { logger.info(userName + " has voted " + estimateValue + " in session " + sessionId); if (!sessionManager.isSessionActive(sessionId)) { throw new IllegalArgumentException("Session not active"); } else if (!CollectionUtils.containsUserEstimate(sessionManager.getResults(sessionId), userName)) { final Estimate estimate = new Estimate(userName, estimateValue); sessionManager.registerEstimate(sessionId, estimate); } messagingUtils.burstResultsMessages(sessionId); } @Autowired  VoteController(SessionManager sessionManager, MessagingUtils messagingUtils); @RequestMapping(value = "vote", method = RequestMethod.POST) void vote(
            @RequestParam(name = "sessionId") final Long sessionId,
            @RequestParam(name = "userName") final String userName,
            @RequestParam(name = "estimateValue") final String estimateValue
    );  }
@Test public void testVote() throws Exception { when(sessionManager.isSessionActive(SESSION_ID)).thenReturn(true); voteController.vote(SESSION_ID, USER_NAME, ESTIMATE_VALUE); inOrder.verify(sessionManager, times(1)).isSessionActive(SESSION_ID); inOrder.verify(sessionManager, times(1)).getResults(SESSION_ID); inOrder.verify(sessionManager, times(1)).registerEstimate(SESSION_ID, ESTIMATE); inOrder.verify(messagingUtils, times(1)).burstResultsMessages(SESSION_ID); inOrder.verifyNoMoreInteractions(); }
@Test public void testVoteUserAlreadyVoted() throws Exception { when(sessionManager.isSessionActive(SESSION_ID)).thenReturn(true); when(sessionManager.getResults(SESSION_ID)).thenReturn(Lists.newArrayList(ESTIMATE)); voteController.vote(SESSION_ID, USER_NAME, ESTIMATE_VALUE); inOrder.verify(sessionManager, times(1)).isSessionActive(SESSION_ID); inOrder.verify(sessionManager, times(1)).getResults(SESSION_ID); inOrder.verify(messagingUtils, times(1)).burstResultsMessages(SESSION_ID); inOrder.verifyNoMoreInteractions(); }
@Test(expected = IllegalArgumentException.class) public void testVoteInvalidSession() throws Exception { when(sessionManager.isSessionActive(SESSION_ID)).thenReturn(false); voteController.vote(SESSION_ID, USER_NAME, ESTIMATE_VALUE); }