### Question:
MainController { @RequestMapping(value = "/game/{gameId}/join", method = RequestMethod.POST) public void joinGame(@PathVariable Long gameId, @RequestBody JoinRequest joinRequest) throws Exception { LOGGER.info(String.format("Inside join game mapping. Id: %d, Name: %s", gameId, joinRequest.getName())); String name = joinRequest.getName(); Game game = repoUtil.findGameById(gameId); if (!game.getPhase().equals("joining")) { LOGGER.error(String.format("%s tried to join game %d after phase has closed", name, gameId)); throw new Exception("Sorry, the joining phase has closed"); } if (exists(game, name)) { LOGGER.error(String.format("%s already exists for game %d", name, gameId)); throw new ContenderAlreadyExistsException(name + " already exists for game: " + gameId.toString()); } if (game.getContenders().size() == 8) { } else { LOGGER.info(name + " joined game: " + gameId.toString()); contenderRepository.save( new Contender(game, name)); } }  @RequestMapping(value = "/init", method = RequestMethod.POST) @ResponseBody InitResponse initGame(); @RequestMapping(value = "/game/{gameId}/join", method = RequestMethod.POST) void joinGame(@PathVariable Long gameId, @RequestBody JoinRequest joinRequest); @RequestMapping(value = "/game/{gameId}/end", method = RequestMethod.POST) void endGame(@PathVariable Long gameId);  }### Answer:
@Test public void giveGameIdExists_whenCallingJoinGame_thenJoinGame() throws Exception { Game game = new Game(); game.setPhase("joining"); game.setContenders(new ArrayList<>()); JoinRequest joinRequest = new JoinRequest(); joinRequest.setName("Liz"); doReturn(null).when(contenderRepository).findByGameAndName(game, joinRequest.getName()); doReturn(game).when(repoUtil).findGameById(1L); mockMvc.perform(post("/game/1/join").contentType(MediaType.APPLICATION_JSON) .content("{\"name\": \"Anthony\"}")) .andExpect(status().isOk()); mainControllerMock.joinGame(1L, joinRequest); verify(contenderRepository, times(2)).save(any(Contender.class)); }