### Question:
RepoUtil { public QuestionAnswer findQuestionAnswerById(Long id) throws Exception { QuestionAnswer questionAnswer = questionAnswerRepository.findById(id).orElse(null); if (questionAnswer == null) { throw new Exception("Invalid question answer id of: " + id.toString()); } return questionAnswer; }  Game findGameById(Long id); QuestionAnswer findQuestionAnswerById(Long id); Contender findContenderByNameAndGameId(String name, Long gameId); Contender findContenderByNameAndGame(String name, Game game);  }### Answer:
@Test public void givenValidQuestionAnswerId_whenCallingFindQuestionAnswerById_thenReturnsCorrectQuestionAnswer() throws Exception { QuestionAnswer questionAnswer = new QuestionAnswer(); questionAnswer.setId(1L); questionAnswer.setScore(1); doReturn(Optional.of(questionAnswer)).when(questionAnswerRepository).findById(1L); QuestionAnswer returnedQuestionAnswer = repoUtil.findQuestionAnswerById(1L); assertEquals(questionAnswer, returnedQuestionAnswer); verify(questionAnswerRepository).findById(1L); }
@Test(expected = Exception.class) public void givenInvalidQuestionAnswerId_whenCallingFindQuestionAnswerById_thenThrowsException() throws Exception { repoUtil.findQuestionAnswerById(1L); }