### Question:
RepoUtil { public Game findGameById(Long id) throws InvalidGameIdException { Game game = gameRepository.findById(id).orElse(null); if (game == null) { throw new InvalidGameIdException("Invalid game of id: " + id.toString()); } return game; }  Game findGameById(Long id); QuestionAnswer findQuestionAnswerById(Long id); Contender findContenderByNameAndGameId(String name, Long gameId); Contender findContenderByNameAndGame(String name, Game game);  }### Answer:
@Test public void givenAValidGameId_whenCallingFindGameById_thenReturnsCorrectGame() throws InvalidGameIdException { Game game = new Game(); game.setPhase("test phase"); game.setId(1L); doReturn(Optional.of(game)).when(gameRepository).findById(1L); Game returnedGame = repoUtil.findGameById(1L); assertEquals(game, returnedGame); verify(gameRepository).findById(1L); }
@Test(expected = InvalidGameIdException.class) public void givenAnInvalidGameId_whenCallingFindGameById_thenThrowsInvalidGameIdException() throws InvalidGameIdException { repoUtil.findGameById(1L); }