### Question:
GameMasterController { @RequestMapping(value = "/game/{gameId}/final-results", method = RequestMethod.GET) public @ResponseBody FinalResultsResponse getFinalResults(@PathVariable Long gameId) throws InvalidGameIdException { Game game = repoUtil.findGameById(gameId); if (!game.getPhase().equals("final results")) { game.setPhase("final results"); gameRepository.save(game); } return new FinalResultsResponse(game.getContenders()); }  @RequestMapping(value = "/game/{gameId}/contender-names", method = RequestMethod.GET) @ResponseBody ContenderNamesResponse getContenderNames(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/start-game", method = RequestMethod.POST) void startGame(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/start-round", method = RequestMethod.POST) void startRound(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/start-voting", method = RequestMethod.POST) void startVoting(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/question-votes", method = RequestMethod.GET) @ResponseBody QuestionVotesResponse getQuestionVotes(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/set-next-to-score", method = RequestMethod.POST) void setNextToScore(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/final-results", method = RequestMethod.GET) @ResponseBody FinalResultsResponse getFinalResults(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/all-votes-submitted", method = RequestMethod.GET) @ResponseBody AllVotesSubmitted allVotesSubmitted(@PathVariable Long gameId); @RequestMapping(value = "/game/{gameId}/more-to-vote-on", method = RequestMethod.GET) @ResponseBody MoreToVoteOn moreQuestionsToVoteOn(@PathVariable Long gameId);  }### Answer:
@Test public void givenValidGameIdAndGameHasContenders_whenCallingGetFinalResults_thenReturnAllOfTheContenders() throws Exception { Contender contender = new Contender(); contender.setId(1L); contender.setName("contender name"); Game game = new Game(); game.setPhase("test"); game.setContenders(Collections.singletonList(contender)); Set<Contender> expectedContenders = new HashSet<>(); expectedContenders.add(contender); doReturn(game).when(repoUtil).findGameById(1L); mockMvc.perform(get("/game/1/final-results").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().json("{\"contenders\":[{\"id\":1, \"name\":\"contender name\"}]}")); FinalResultsResponse finalResultsResponse = gameMasterController.getFinalResults(1L); assertEquals(expectedContenders, finalResultsResponse.getContenders()); }
@Test(expected = Exception.class) public void givenOnlyOnePersonInGameId_whenCallingStartGame_thenThrowException() throws Exception { Game game = new Game(); Set<Contender> contenders = new HashSet<>(); contenders.add(new Contender()); game.setContenders(contenders); doReturn(game).when(repoUtil).findGameById(1L); mockMvc.perform(post("/game/1/start-game")) .andExpect(status().isInternalServerError()); gameMasterController.getFinalResults(1L); }