### Question:
RepoUtil { public Contender findContenderByNameAndGame(String name, Game game) throws Exception { Contender contender = contenderRepository.findByGameAndName(game, name); if (contender == null) { throw new Exception("Invalid contender with name: " + name + " and gameId: " + game.getId().toString()); } return contender; }  Game findGameById(Long id); QuestionAnswer findQuestionAnswerById(Long id); Contender findContenderByNameAndGameId(String name, Long gameId); Contender findContenderByNameAndGame(String name, Game game);  }### Answer:
@Test public void givenValidName_whenCallingFindContenderByNameAndGame_thenReturnsCorrectContender() throws Exception { Contender contender = new Contender(); contender.setName("contender name"); contender.setId(1L); contender.setScore(1000L); Game game = new Game(); game.setId(1L); doReturn(contender).when(contenderRepository).findByGameAndName(game, "name"); Contender returnedContender = repoUtil.findContenderByNameAndGame("name", game); assertEquals(contender, returnedContender); verify(contenderRepository).findByGameAndName(game, "name"); }
@Test(expected = Exception.class) public void givenInvalidName_whenCallingFindContenderByNameAndGame_thenThrowsException() throws Exception { repoUtil.findContenderByNameAndGame("name", new Game()); }