### Question:
JudgmentKeywordCreator { public JudgmentKeyword getOrCreateJudgmentKeyword(CourtType courtType, String phrase) { JudgmentKeyword keyword = judgmentKeywordRepository.findOneByCourtTypeAndPhraseIgnoreCase(courtType, phrase); if (keyword == null) { keyword = new JudgmentKeyword(courtType, phrase); judgmentKeywordRepository.save(keyword); judgmentKeywordRepository.flush(); } return keyword; }  JudgmentKeyword getOrCreateJudgmentKeyword(CourtType courtType, String phrase); @Autowired void setJudgmentKeywordRepository(JudgmentKeywordRepository judgmentKeywordRepository);  }### Answer:
@Test public void getOrCreateJudgmentKeyword_Create() { String phrase = keyword.getPhrase() + "YYY"; CourtType courtType = CourtType.COMMON; JudgmentKeyword foundKeyword = keywordCreator.getOrCreateJudgmentKeyword(courtType, phrase); verify(judgmentKeywordRepository).save(Mockito.any(JudgmentKeyword.class)); verify(judgmentKeywordRepository).findOneByCourtTypeAndPhraseIgnoreCase(courtType, phrase); assertFalse(foundKeyword == keyword); assertEquals(new JudgmentKeyword(courtType, phrase), foundKeyword); }
@Test public void getOrCreateJudgmentKeyword_Get() { String phrase = keyword.getPhrase(); CourtType courtType = CourtType.COMMON; JudgmentKeyword foundKeyword = keywordCreator.getOrCreateJudgmentKeyword(courtType, phrase); verify(judgmentKeywordRepository, never()).save(Mockito.any(JudgmentKeyword.class)); verify(judgmentKeywordRepository).findOneByCourtTypeAndPhraseIgnoreCase(courtType, phrase); assertEquals(phrase, foundKeyword.getPhrase()); assertTrue(foundKeyword == keyword); }