@Test public void shouldGetEstimateValuesForFacilityWhenEstimatesWereSaved() throws Exception { List<AnnualFacilityEstimateEntry> list = asList(new AnnualFacilityEstimateEntry()); when(repository.getFacilityEstimateWithDetails(2005, 2L, 2L)).thenReturn(list); List<AnnualFacilityEstimateEntry> response = service.getEstimateValuesForFacility(2L, 2L, 2005); assertThat(response, is(list)); verify(facilityService, never()).getById(any(Long.class)); verify(estimateCategoryService, never()).getAll(); }
public List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year) { List<AnnualFacilityEstimateEntry> estimates = repository.getFacilityEstimateWithDetails(year, facilityId, programId); if (CollectionUtils.isEmpty(estimates)) { Facility facility = facilityService.getById(facilityId); List<EstimateCategory> categories = estimateCategoryService.getAll(); estimates = createDefaultEstimateEntries(categories, facility.getId(), programId, year, true); for (AnnualFacilityEstimateEntry estimate : estimates) { estimate.calculateAndSetValue(facility.getCatchmentPopulation()); } } return estimates; }
AnnualFacilityDemographicEstimateService { public List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year) { List<AnnualFacilityEstimateEntry> estimates = repository.getFacilityEstimateWithDetails(year, facilityId, programId); if (CollectionUtils.isEmpty(estimates)) { Facility facility = facilityService.getById(facilityId); List<EstimateCategory> categories = estimateCategoryService.getAll(); estimates = createDefaultEstimateEntries(categories, facility.getId(), programId, year, true); for (AnnualFacilityEstimateEntry estimate : estimates) { estimate.calculateAndSetValue(facility.getCatchmentPopulation()); } } return estimates; } }
AnnualFacilityDemographicEstimateService { public List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year) { List<AnnualFacilityEstimateEntry> estimates = repository.getFacilityEstimateWithDetails(year, facilityId, programId); if (CollectionUtils.isEmpty(estimates)) { Facility facility = facilityService.getById(facilityId); List<EstimateCategory> categories = estimateCategoryService.getAll(); estimates = createDefaultEstimateEntries(categories, facility.getId(), programId, year, true); for (AnnualFacilityEstimateEntry estimate : estimates) { estimate.calculateAndSetValue(facility.getCatchmentPopulation()); } } return estimates; }  }
AnnualFacilityDemographicEstimateService { public List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year) { List<AnnualFacilityEstimateEntry> estimates = repository.getFacilityEstimateWithDetails(year, facilityId, programId); if (CollectionUtils.isEmpty(estimates)) { Facility facility = facilityService.getById(facilityId); List<EstimateCategory> categories = estimateCategoryService.getAll(); estimates = createDefaultEstimateEntries(categories, facility.getId(), programId, year, true); for (AnnualFacilityEstimateEntry estimate : estimates) { estimate.calculateAndSetValue(facility.getCatchmentPopulation()); } } return estimates; }  void save(EstimateForm estimateForm, Long userId); void finalizeEstimate(EstimateForm form, Long userId); void undoFinalize(EstimateForm form, Long userId); EstimateForm getEstimateForm(Long userId, Long programId, Integer year); List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year); }
AnnualFacilityDemographicEstimateService { public List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year) { List<AnnualFacilityEstimateEntry> estimates = repository.getFacilityEstimateWithDetails(year, facilityId, programId); if (CollectionUtils.isEmpty(estimates)) { Facility facility = facilityService.getById(facilityId); List<EstimateCategory> categories = estimateCategoryService.getAll(); estimates = createDefaultEstimateEntries(categories, facility.getId(), programId, year, true); for (AnnualFacilityEstimateEntry estimate : estimates) { estimate.calculateAndSetValue(facility.getCatchmentPopulation()); } } return estimates; }  void save(EstimateForm estimateForm, Long userId); void finalizeEstimate(EstimateForm form, Long userId); void undoFinalize(EstimateForm form, Long userId); EstimateForm getEstimateForm(Long userId, Long programId, Integer year); List<AnnualFacilityEstimateEntry> getEstimateValuesForFacility(Long facilityId, Long programId, Integer year);  }