@Test public void shouldGetPeriodForGivenFacilityProgramAndDate() { Long programId = 1L; Long requisitionGroupId = 2L; Long scheduleId = 3L; Program program = new Program(programId); Facility facility = new Facility(); RequisitionGroup requisitionGroup = new RequisitionGroup(); requisitionGroup.setId(requisitionGroupId); when(requisitionGroupRepository.getRequisitionGroupForProgramAndFacility(program, facility)).thenReturn(requisitionGroup); RequisitionGroupProgramSchedule schedule = new RequisitionGroupProgramSchedule(); ProcessingSchedule processingSchedule = new ProcessingSchedule(scheduleId); schedule.setProcessingSchedule(processingSchedule); when(requisitionGroupProgramScheduleRepository.getScheduleForRequisitionGroupAndProgram(requisitionGroupId, programId)).thenReturn(schedule); Date date = new Date(); ProcessingPeriod expectedPeriod = new ProcessingPeriod(); when(periodRepository.getPeriodForDate(scheduleId, date)).thenReturn(expectedPeriod); ProcessingPeriod periodForDate = service.getPeriodForDate(facility, program, date); verify(periodRepository).getPeriodForDate(scheduleId, date); assertThat(periodForDate, is(expectedPeriod)); }
public ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getPeriodForDate(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), date); }
ProcessingScheduleService { public ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getPeriodForDate(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), date); } }
ProcessingScheduleService { public ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getPeriodForDate(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), date); } @Autowired  ProcessingScheduleService(ProcessingScheduleRepository scheduleRepository, ProcessingPeriodRepository periodRepository,
                                   RequisitionGroupRepository requisitionGroupRepository, RequisitionGroupProgramScheduleRepository requisitionGroupProgramScheduleRepository); }
ProcessingScheduleService { public ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getPeriodForDate(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), date); } @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 ProcessingPeriod getPeriodForDate(Facility facility, Program program, Date date) { RequisitionGroupProgramSchedule requisitionGroupProgramSchedule = getSchedule(facility, program); return periodRepository.getPeriodForDate(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), date); } @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);  }