### Question:
CycleService { public Cycle findById(Long cycleId) { return cycleRepository.findByIdOrThrow(cycleId); } @Autowired  CycleService(
      CyclePreparationCloningService cyclePreparationCloningService,
      CycleRepository cycleRepository,
      CompanyHistoryRepository companyHistoryRepository,
      CompanyService companyService); Collection<Cycle> getAllCycles(); Cycle findById(Long cycleId); @Transactional Cycle updateCycle(Cycle updatedCycle); @Transactional void deleteCycle(Long cycleId, User user); @Transactional Cycle defineCycle(Long oldCycleId, Cycle cycle); @EventListener(ApplicationReadyEvent.class) void applicationStartCycleProcessing(); @Scheduled(cron = threeInTheMorningCronExpr) void dailyCycleProcessing(); @Transactional void processAutomaticCycleSwitch();  }### Answer:
@Test(expected = EntityNotFoundException.class) public void findById_expectedNoMatch() { long searchId = 100L; when(cycleRepository.findByIdOrThrow(searchId)).thenThrow(new EntityNotFoundException()); cycleService.findById(searchId); }
@Test public void findById_expectedFoundResult() { long searchId = 100L; Cycle expectedCycle = new Cycle("TestCycle"); when(cycleRepository.findByIdOrThrow(searchId)).thenReturn(expectedCycle); Cycle actualCycle = cycleService.findById(searchId); Assert.assertEquals(expectedCycle, actualCycle); }