@Test public void shouldGetEstimateValuesForFacilityWhenDemographicEstimateIsSaved() throws Exception { List<AnnualFacilityEstimateEntry> list = asList(make(an(AnnualFacilityEstimateBuilder.defaultAnnualFacilityEstimateEntry))); when(repository.getFacilityEstimateWithDetails(2015, 20L, 3L)).thenReturn(list); List<AnnualFacilityEstimateEntry> result = service.getEstimateValuesForFacility(20L, 3L, 2015); assertThat(result,is(list)); }
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);  }