@Test public void shouldGetAllPeriodsInDateRange() throws Exception { Long scheduleId = 1L; Date startDate = DateTime.now().toDate(); Date endDate = DateTime.now().toDate(); List<ProcessingPeriod> expected = new ArrayList<>(); Facility facility = new Facility(1L); Program program = new Program(2L); RequisitionGroup requisitionGroup = new RequisitionGroup(); requisitionGroup.setId(1L); ProcessingSchedule processingSchedule = new ProcessingSchedule(); processingSchedule.setId(scheduleId); RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = make(a(defaultRequisitionGroupProgramSchedule)); requisitionGroupProgramSchedule.setProcessingSchedule(processingSchedule); when(requisitionGroupRepository.getRequisitionGroupForProgramAndFacility(program, facility)).thenReturn(requisitionGroup); when(requisitionGroupProgramScheduleRepository.getScheduleForRequisitionGroupAndProgram( requisitionGroup.getId(), program.getId())).thenReturn(requisitionGroupProgramSchedule); when(periodRepository.getAllPeriodsForDateRange(scheduleId, startDate, endDate)).thenReturn(expected); List<ProcessingPeriod> actual = service.getAllPeriodsForDateRange(facility, program, startDate, endDate); verify(periodRepository).getAllPeriodsForDateRange(scheduleId, startDate, endDate); assertThat(actual, is(expected)); }
public List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getAllPeriodsForDateRange(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), startDate, endDate); }
ProcessingScheduleService { public List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getAllPeriodsForDateRange(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), startDate, endDate); } }
ProcessingScheduleService { public List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getAllPeriodsForDateRange(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), startDate, endDate); } @Autowired  ProcessingScheduleService(ProcessingScheduleRepository scheduleRepository, ProcessingPeriodRepository periodRepository,
                                   RequisitionGroupRepository requisitionGroupRepository, RequisitionGroupProgramScheduleRepository requisitionGroupProgramScheduleRepository); }
ProcessingScheduleService { public List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getAllPeriodsForDateRange(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), startDate, endDate); } @Autowired  ProcessingScheduleService(ProcessingScheduleRepository scheduleRepository, ProcessingPeriodRepository periodRepository,
                                   RequisitionGroupRepository requisitionGroupRepository, RequisitionGroupProgramScheduleRepository requisitionGroupProgramScheduleRepository); List<ProcessingSchedule> getAll(); ProcessingSchedule save(ProcessingSchedule processingSchedule); List<ProcessingPeriod> getAllPeriods(Long scheduleId); ProcessingSchedule get(Long id); void savePeriod(ProcessingPeriod processingPeriod); void deletePeriod(Long processingPeriodId); List<ProcessingPeriod> getAllPeriodsAfterDateAndPeriod(Long facilityId, Long programId, Date programStartDate, Long startingPeriodId); List<ProcessingPeriod> getOpenPeriods(Long facilityId, Long programId, Long startingPeriodId); ProcessingPeriod getPeriodById(Long periodId); List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate); List<ProcessingPeriod> getUsedPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate); ProcessingSchedule getByCode(String code); List<ProcessingPeriod> getAllPeriodsBefore(Long scheduleId, Date beforeDate); ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date); ProcessingPeriod getCurrentPeriod(Long facilityId, Long programId, Date programStartDate); List<ProcessingPeriod> getNPreviousPeriodsInDescOrder(ProcessingPeriod currentPeriod, Integer n); Integer findM(ProcessingPeriod period); List<ProcessingPeriod> getAllPeriodsForScheduleAndYear(Long scheduleId, Long year); }
ProcessingScheduleService { public List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getAllPeriodsForDateRange(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), startDate, endDate); } @Autowired  ProcessingScheduleService(ProcessingScheduleRepository scheduleRepository, ProcessingPeriodRepository periodRepository,
                                   RequisitionGroupRepository requisitionGroupRepository, RequisitionGroupProgramScheduleRepository requisitionGroupProgramScheduleRepository); List<ProcessingSchedule> getAll(); ProcessingSchedule save(ProcessingSchedule processingSchedule); List<ProcessingPeriod> getAllPeriods(Long scheduleId); ProcessingSchedule get(Long id); void savePeriod(ProcessingPeriod processingPeriod); void deletePeriod(Long processingPeriodId); List<ProcessingPeriod> getAllPeriodsAfterDateAndPeriod(Long facilityId, Long programId, Date programStartDate, Long startingPeriodId); List<ProcessingPeriod> getOpenPeriods(Long facilityId, Long programId, Long startingPeriodId); ProcessingPeriod getPeriodById(Long periodId); List<ProcessingPeriod> getAllPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate); List<ProcessingPeriod> getUsedPeriodsForDateRange(Facility facility, Program program, Date startDate, Date endDate); ProcessingSchedule getByCode(String code); List<ProcessingPeriod> getAllPeriodsBefore(Long scheduleId, Date beforeDate); ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date); ProcessingPeriod getCurrentPeriod(Long facilityId, Long programId, Date programStartDate); List<ProcessingPeriod> getNPreviousPeriodsInDescOrder(ProcessingPeriod currentPeriod, Integer n); Integer findM(ProcessingPeriod period); List<ProcessingPeriod> getAllPeriodsForScheduleAndYear(Long scheduleId, Long year);  }