@Test public void shouldNotThrowErrorForIfPeriodMatchesCurrentPeriodForNonVirtualFacility() throws Exception { ProcessingPeriod processingPeriod = new ProcessingPeriod(1L); Facility reportingFacility = new Facility(); Program reportingProgram = new Program(); when(requisitionService.getCurrentPeriod(any(RequisitionSearchCriteria.class))).thenReturn(processingPeriod); when(requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram)).thenReturn(processingPeriod); restRequisitionCalculator.validatePeriod(reportingFacility, reportingProgram); }
public void validatePeriod(Facility reportingFacility, Program reportingProgram) { if (!reportingFacility.getVirtualFacility()) { RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); if (requisitionService.getCurrentPeriod(searchCriteria) != null && !requisitionService.getCurrentPeriod(searchCriteria).getId().equals (requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram).getId())) { throw new DataException("error.rnr.previous.not.filled"); } } }
RestRequisitionCalculator { public void validatePeriod(Facility reportingFacility, Program reportingProgram) { if (!reportingFacility.getVirtualFacility()) { RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); if (requisitionService.getCurrentPeriod(searchCriteria) != null && !requisitionService.getCurrentPeriod(searchCriteria).getId().equals (requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram).getId())) { throw new DataException("error.rnr.previous.not.filled"); } } } }
RestRequisitionCalculator { public void validatePeriod(Facility reportingFacility, Program reportingProgram) { if (!reportingFacility.getVirtualFacility()) { RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); if (requisitionService.getCurrentPeriod(searchCriteria) != null && !requisitionService.getCurrentPeriod(searchCriteria).getId().equals (requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram).getId())) { throw new DataException("error.rnr.previous.not.filled"); } } }  }
RestRequisitionCalculator { public void validatePeriod(Facility reportingFacility, Program reportingProgram) { if (!reportingFacility.getVirtualFacility()) { RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); if (requisitionService.getCurrentPeriod(searchCriteria) != null && !requisitionService.getCurrentPeriod(searchCriteria).getId().equals (requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram).getId())) { throw new DataException("error.rnr.previous.not.filled"); } } }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition); }
RestRequisitionCalculator { public void validatePeriod(Facility reportingFacility, Program reportingProgram) { if (!reportingFacility.getVirtualFacility()) { RequisitionSearchCriteria searchCriteria = new RequisitionSearchCriteria(); searchCriteria.setProgramId(reportingProgram.getId()); searchCriteria.setFacilityId(reportingFacility.getId()); if (requisitionService.getCurrentPeriod(searchCriteria) != null && !requisitionService.getCurrentPeriod(searchCriteria).getId().equals (requisitionService.getPeriodForInitiating(reportingFacility, reportingProgram).getId())) { throw new DataException("error.rnr.previous.not.filled"); } } }  void validatePeriod(Facility reportingFacility, Program reportingProgram); void validateCustomPeriod(Facility reportingFacility, Program reportingProgram, ProcessingPeriod period, Long userId); void validateProducts(List<RnrLineItem> products, Rnr savedRequisition); Rnr setDefaultValues(Rnr requisition);  }