@Test public void shouldGetEstimateValuesForFacilityWhenEstimatesAreNotFound() throws Exception{ EstimateCategory category1 = new EstimateCategory(); category1.setDefaultConversionFactor(50.0); EstimateCategory category2 = new EstimateCategory(); category2.setDefaultConversionFactor(5.0); Facility facility = new Facility(); facility.setCatchmentPopulation(20000L); when(facilityService.getById(2L)).thenReturn(facility); when(estimateCategoryService.getAll()).thenReturn(asList(category1, category2)); when(repository.getFacilityEstimate(2005, 2L, 2L)).thenReturn(null); List<AnnualFacilityEstimateEntry> response = service.getEstimateValuesForFacility(2L, 2L, 2005); assertThat(response.size(), is(2)); assertThat(response.get(0).getValue(), is(10000L)); assertThat(response.get(1).getValue(), is(1000L)); verify(estimateCategoryService, atMost(1)).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);  }