### Question:
JudgmentMeansOfAppealCreator { public MeansOfAppeal fetchOrCreateMeansOfAppeal(CourtType courtType, String name) { MeansOfAppeal meansOfAppeal = meansOfAppealRepository.findOneByCourtTypeAndNameIgnoreCase(courtType, name); if (meansOfAppeal == null) { meansOfAppeal = new MeansOfAppeal(courtType, name); meansOfAppealRepository.save(meansOfAppeal); meansOfAppealRepository.flush(); } return meansOfAppeal; }  MeansOfAppeal fetchOrCreateMeansOfAppeal(CourtType courtType, String name); @Autowired void setMeansOfAppealRepository(MeansOfAppealRepository meansOfAppealRepository);  }### Answer:
@Test public void fetchOrCreateMeansOfAppeal_FETCH() { MeansOfAppeal meansOfAppeal = new MeansOfAppeal(CourtType.SUPREME, "text"); when(meansOfAppealRepository.findOneByCourtTypeAndNameIgnoreCase(meansOfAppeal.getCourtType(), meansOfAppeal.getName())) .thenReturn(meansOfAppeal); MeansOfAppeal retMeansOfAppeal = meansOfAppealCreator.fetchOrCreateMeansOfAppeal(meansOfAppeal.getCourtType(), meansOfAppeal.getName()); assertTrue(meansOfAppeal == retMeansOfAppeal); verify(meansOfAppealRepository).findOneByCourtTypeAndNameIgnoreCase(meansOfAppeal.getCourtType(), meansOfAppeal.getName()); verifyNoMoreInteractions(meansOfAppealRepository); }
@Test public void fetchOrCreateMeansOfAppeal_CREATE() { MeansOfAppeal retMeansOfAppeal = meansOfAppealCreator.fetchOrCreateMeansOfAppeal(CourtType.SUPREME, "text"); assertEquals(new MeansOfAppeal(CourtType.SUPREME, "text"), retMeansOfAppeal); verify(meansOfAppealRepository).findOneByCourtTypeAndNameIgnoreCase(CourtType.SUPREME, "text"); verify(meansOfAppealRepository).save(new MeansOfAppeal(CourtType.SUPREME, "text")); verify(meansOfAppealRepository).flush(); verifyNoMoreInteractions(meansOfAppealRepository); }