### Question:
CycleService { @Transactional public void deleteCycle(Long cycleId, User user) throws Exception { Cycle cycle = cycleRepository.findByIdOrThrow(cycleId); if (cycle.getCycleState() != CycleState.ACTIVE) { cycle .getCompanies() .forEach(company -> companyService.deleteCompany(company.getId(), false, user)); this.logger.info("Deleted (non active) cycle with id " + cycle.getId()); } else { throw new Exception("An active Cycle can not be deleted"); } } @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 deleteCycle_expectedEntityNotFoundException() throws Exception { Cycle cycle = createDummyCycle("c", 42, 1); when(cycleRepository.findByIdOrThrow(anyLong())).thenThrow(new EntityNotFoundException()); cycleService.deleteCycle(cycle.getId(), mockedUser); }
@Test public void deleteCycle_expectedToBeDeleted() throws Exception { Cycle cycle = createDummyCycle("c", 42, 1); when(cycleRepository.findByIdOrThrow(cycle.getId())).thenReturn(cycle); cycleService.deleteCycle(cycle.getId(), mockedUser); }