### Question:
JudgmentResultCreator { public JudgmentResult fetchOrCreateJudgmentResult(CourtType courtType, String text) { JudgmentResult judgmentResult = judgmentResultRepository.findOneByCourtTypeAndTextIgnoreCase(courtType, text); if (judgmentResult == null) { judgmentResult = new JudgmentResult(courtType, text); judgmentResultRepository.save(judgmentResult); judgmentResultRepository.flush(); } return judgmentResult; }  JudgmentResult fetchOrCreateJudgmentResult(CourtType courtType, String text); @Autowired void setJudgmentResultRepository(JudgmentResultRepository judgmentResultRepository);  }### Answer:
@Test public void fetchOrCreateJudgmentResult_FETCH() { JudgmentResult judgmentResult = new JudgmentResult(CourtType.SUPREME, "text"); when(judgmentResultRepository.findOneByCourtTypeAndTextIgnoreCase(judgmentResult.getCourtType(), judgmentResult.getText())) .thenReturn(judgmentResult); JudgmentResult retJudgmentResult = judgmentResultCreator.fetchOrCreateJudgmentResult(judgmentResult.getCourtType(), judgmentResult.getText()); assertTrue(judgmentResult == retJudgmentResult); verify(judgmentResultRepository).findOneByCourtTypeAndTextIgnoreCase(judgmentResult.getCourtType(), judgmentResult.getText()); verifyNoMoreInteractions(judgmentResultRepository); }
@Test public void fetchOrCreateJudgmentResult_CREATE() { JudgmentResult retJudgmentResult = judgmentResultCreator.fetchOrCreateJudgmentResult(CourtType.SUPREME, "text"); assertEquals(new JudgmentResult(CourtType.SUPREME, "text"), retJudgmentResult); verify(judgmentResultRepository).findOneByCourtTypeAndTextIgnoreCase(CourtType.SUPREME, "text"); verify(judgmentResultRepository).save(new JudgmentResult(CourtType.SUPREME, "text")); verify(judgmentResultRepository).flush(); verifyNoMoreInteractions(judgmentResultRepository); }