@Test public void shouldUseRequisitionOnlyStrategyIfLineItemsAreNotRequired() throws Exception { Long facilityId = 1L, programId = null, periodId = 4L; RequisitionSearchCriteria criteria = make(a(defaultSearchCriteria, with(facilityIdProperty, facilityId), with(programIdProperty, programId), with(periodIdProperty, periodId), with(withoutLineItemFlag, true))); whenNew(RequisitionOnlySearch.class) .withArguments(criteria, requisitionPermissionService, requisitionRepository) .thenReturn(mock(RequisitionOnlySearch.class)); RequisitionSearchStrategy facilityDateRangeStrategy = requisitionSearchStrategyFactory.getSearchStrategy(criteria); assertTrue(facilityDateRangeStrategy instanceof RequisitionOnlySearch); verifyNew(RequisitionOnlySearch.class).withArguments(criteria, requisitionPermissionService, requisitionRepository); }
public RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria) { if (criteria.isEmergency()) { return new EmergencyRequisitionSearch(criteria, permissionService, repository); } else if (criteria.isWithoutLineItems()) { return new RequisitionOnlySearch(criteria, permissionService, repository); } else if (criteria.getProgramId() == null) { return new FacilityDateRangeSearch(criteria, permissionService, scheduleService, repository, programService); } else { return new FacilityProgramDateRangeSearch(criteria, permissionService, scheduleService, repository); } }
RequisitionSearchStrategyFactory { public RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria) { if (criteria.isEmergency()) { return new EmergencyRequisitionSearch(criteria, permissionService, repository); } else if (criteria.isWithoutLineItems()) { return new RequisitionOnlySearch(criteria, permissionService, repository); } else if (criteria.getProgramId() == null) { return new FacilityDateRangeSearch(criteria, permissionService, scheduleService, repository, programService); } else { return new FacilityProgramDateRangeSearch(criteria, permissionService, scheduleService, repository); } } }
RequisitionSearchStrategyFactory { public RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria) { if (criteria.isEmergency()) { return new EmergencyRequisitionSearch(criteria, permissionService, repository); } else if (criteria.isWithoutLineItems()) { return new RequisitionOnlySearch(criteria, permissionService, repository); } else if (criteria.getProgramId() == null) { return new FacilityDateRangeSearch(criteria, permissionService, scheduleService, repository, programService); } else { return new FacilityProgramDateRangeSearch(criteria, permissionService, scheduleService, repository); } }  }
RequisitionSearchStrategyFactory { public RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria) { if (criteria.isEmergency()) { return new EmergencyRequisitionSearch(criteria, permissionService, repository); } else if (criteria.isWithoutLineItems()) { return new RequisitionOnlySearch(criteria, permissionService, repository); } else if (criteria.getProgramId() == null) { return new FacilityDateRangeSearch(criteria, permissionService, scheduleService, repository, programService); } else { return new FacilityProgramDateRangeSearch(criteria, permissionService, scheduleService, repository); } }  RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria); }
RequisitionSearchStrategyFactory { public RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria) { if (criteria.isEmergency()) { return new EmergencyRequisitionSearch(criteria, permissionService, repository); } else if (criteria.isWithoutLineItems()) { return new RequisitionOnlySearch(criteria, permissionService, repository); } else if (criteria.getProgramId() == null) { return new FacilityDateRangeSearch(criteria, permissionService, scheduleService, repository, programService); } else { return new FacilityProgramDateRangeSearch(criteria, permissionService, scheduleService, repository); } }  RequisitionSearchStrategy getSearchStrategy(RequisitionSearchCriteria criteria);  }