### Question:
CycleService { @Transactional public Cycle updateCycle(Cycle updatedCycle) { Cycle referencedCycle = cycleRepository.findByIdOrThrow(updatedCycle.getId()); updateReferencedCycle(updatedCycle, referencedCycle); logger.info("Updated cycle with id: " + referencedCycle.getId()); return cycleRepository.save(referencedCycle); } @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 updateCycle_noOriginalCycle_expectedNoMatchException() { long cycleId = 100L; String oldCycleName = "OldCycleName"; int oldMonthDelay = 0; Cycle cycleToUpdate = createDummyCycle(oldCycleName, cycleId, oldMonthDelay); when(cycleRepository.findByIdOrThrow(cycleId)).thenThrow(new EntityNotFoundException()); cycleService.updateCycle(cycleToUpdate); }
@Test public void updateCycle_expectedUpdatedCycle() { long cycleId = 100L; String oldCycleName = "OldCycleName"; int oldCycleDelay = 1; String newCycleName = "NewCycleName"; int newCycleDelay = 2; Cycle cycleToUpdate = createDummyCycle(oldCycleName, cycleId, oldCycleDelay); Cycle expectedCycle = createDummyCycle(newCycleName, cycleId, newCycleDelay); ArgumentCaptor<Cycle> capturedCycle = ArgumentCaptor.forClass(Cycle.class); when(cycleRepository.findByIdOrThrow(cycleId)).thenReturn(cycleToUpdate); when(cycleRepository.save(any(Cycle.class))).thenReturn(expectedCycle); Cycle actualCycle = cycleService.updateCycle(expectedCycle); verify(cycleRepository).save(capturedCycle.capture()); assertCycles(expectedCycle, capturedCycle.getValue()); assertCycles(expectedCycle, actualCycle); }