@Test public void shouldGetDataForADistribution() throws Exception { Distribution distribution = new Distribution(); DeliveryZone zone = new DeliveryZone(5L); Program program = new Program(3L); distribution.setDeliveryZone(zone); distribution.setProgram(program); when(facilityService.getById(2L)).thenReturn(make(a(FacilityBuilder.defaultFacility))); FacilityVisit facilityVisit = new FacilityVisit(); facilityVisit.setId(1L); facilityVisit.setFacilityId(2L); List<FacilityVisit> facilityVisits = asList(facilityVisit); when(facilityVisitService.getUnSyncedFacilities(distribution.getId())).thenReturn(facilityVisits); EpiUse epiUse = new EpiUse(); when(epiUseService.getBy(facilityVisit.getId())).thenReturn(epiUse); EpiInventory epiInventory = new EpiInventory(); when(epiInventoryService.getBy(facilityVisit.getId())).thenReturn(epiInventory); VaccinationFullCoverage vaccinationFullCoverage = new VaccinationFullCoverage(); when(vaccinationCoverageService.getFullCoverageBy(facilityVisit.getId())).thenReturn(vaccinationFullCoverage); VaccinationChildCoverage vaccinationChildCoverage = new VaccinationChildCoverage(); when(vaccinationCoverageService.getChildCoverageBy(facilityVisit.getId())).thenReturn(vaccinationChildCoverage); VaccinationAdultCoverage vaccinationAdultCoverage = new VaccinationAdultCoverage(); when(vaccinationCoverageService.getAdultCoverageBy(facilityVisit.getId())).thenReturn(vaccinationAdultCoverage); Refrigerator refrigerator = new Refrigerator(); refrigerator.setFacilityId(2L); when(refrigeratorService.getRefrigeratorsForADeliveryZoneAndProgram(distribution.getDeliveryZone().getId(), distribution.getProgram().getId())).thenReturn(asList(refrigerator)); RefrigeratorReading refrigeratorReading = new RefrigeratorReading(refrigerator); DistributionRefrigerators distributionRefrigerators = new DistributionRefrigerators(); whenNew(DistributionRefrigerators.class).withArguments(asList(refrigeratorReading)).thenReturn(distributionRefrigerators); FacilityDistribution facilityDistribution = new FacilityDistribution(); whenNew(FacilityDistribution.class).withArguments(facilityVisit, epiUse, distributionRefrigerators, epiInventory, vaccinationFullCoverage, vaccinationChildCoverage, vaccinationAdultCoverage).thenReturn(facilityDistribution); Map<Long, FacilityDistribution> facilityDistributionMap = facilityDistributionService.get(distribution); assertThat(facilityDistributionMap.size(), is(1)); assertThat(facilityDistributionMap.get(facilityVisit.getFacilityId()), is(facilityDistribution)); }
public Map<Long, FacilityDistribution> get(Distribution distribution) { Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<FacilityVisit> unSyncedFacilities = facilityVisitService.getUnSyncedFacilities(distribution.getId()); for (FacilityVisit facilityVisit : unSyncedFacilities) { facilityDistributions.put(facilityVisit.getFacilityId(), getDistributionData(facilityVisit, distribution)); } return facilityDistributions; }
FacilityDistributionService { public Map<Long, FacilityDistribution> get(Distribution distribution) { Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<FacilityVisit> unSyncedFacilities = facilityVisitService.getUnSyncedFacilities(distribution.getId()); for (FacilityVisit facilityVisit : unSyncedFacilities) { facilityDistributions.put(facilityVisit.getFacilityId(), getDistributionData(facilityVisit, distribution)); } return facilityDistributions; } }
FacilityDistributionService { public Map<Long, FacilityDistribution> get(Distribution distribution) { Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<FacilityVisit> unSyncedFacilities = facilityVisitService.getUnSyncedFacilities(distribution.getId()); for (FacilityVisit facilityVisit : unSyncedFacilities) { facilityDistributions.put(facilityVisit.getFacilityId(), getDistributionData(facilityVisit, distribution)); } return facilityDistributions; }  }
FacilityDistributionService { public Map<Long, FacilityDistribution> get(Distribution distribution) { Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<FacilityVisit> unSyncedFacilities = facilityVisitService.getUnSyncedFacilities(distribution.getId()); for (FacilityVisit facilityVisit : unSyncedFacilities) { facilityDistributions.put(facilityVisit.getFacilityId(), getDistributionData(facilityVisit, distribution)); } return facilityDistributions; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution); }
FacilityDistributionService { public Map<Long, FacilityDistribution> get(Distribution distribution) { Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); List<FacilityVisit> unSyncedFacilities = facilityVisitService.getUnSyncedFacilities(distribution.getId()); for (FacilityVisit facilityVisit : unSyncedFacilities) { facilityDistributions.put(facilityVisit.getFacilityId(), getDistributionData(facilityVisit, distribution)); } return facilityDistributions; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution);  }