@Test public void shouldFilterListOfRefrigeratorsForAFacilityAndPopulateFacilityDistributionsWithThem() throws Exception { Facility facility = new Facility(5L); Distribution distribution = new Distribution(); Refrigerator nonFacilityRefrigerator = new Refrigerator(); nonFacilityRefrigerator.setFacilityId(54L); Refrigerator facilityRefrigerator = new Refrigerator(); facilityRefrigerator.setFacilityId(5L); RefrigeratorReading facilityRefReading = new RefrigeratorReading(facilityRefrigerator); List<Refrigerator> refrigerators = asList(nonFacilityRefrigerator, facilityRefrigerator); FacilityDistribution expectedFacilityDistribution = new FacilityDistribution(); expectedFacilityDistribution.setEpiUse(new EpiUse()); FacilityVisit facilityVisit = new FacilityVisit(); whenNew(FacilityVisit.class).withArguments(facility, distribution).thenReturn(facilityVisit); List<TargetGroupProduct> emptyTargetGroupProductList = new ArrayList<>(); whenNew(FacilityDistribution.class).withArguments(facilityVisit, facility, distribution, asList(facilityRefReading), emptyTargetGroupProductList, emptyTargetGroupProductList, null, null).thenReturn(expectedFacilityDistribution); FacilityDistribution facilityDistribution = facilityDistributionService.createDistributionData(facility, distribution, refrigerators, emptyTargetGroupProductList, emptyTargetGroupProductList, null, null); verifyNew(FacilityDistribution.class).withArguments(facilityVisit, facility, distribution, asList(facilityRefReading), emptyTargetGroupProductList, emptyTargetGroupProductList, null, null); assertThat(facilityDistribution, is(expectedFacilityDistribution)); }
FacilityDistribution createDistributionData(final Facility facility, Distribution distribution, List<Refrigerator> refrigerators, List<TargetGroupProduct> childrenTargetGroupProducts, List<TargetGroupProduct> adultTargetGroupProducts, List<ProductVial> childProductVials, List<ProductVial> adultProductVials) { List<RefrigeratorReading> refrigeratorReadings = getRefrigeratorReadings(facility.getId(), refrigerators); FacilityVisit facilityVisit = new FacilityVisit(facility, distribution); facilityVisitService.save(facilityVisit); FacilityDistribution facilityDistribution = new FacilityDistribution(facilityVisit, facility, distribution, refrigeratorReadings, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials); epiUseService.save(facilityDistribution.getEpiUse()); epiInventoryService.save(facilityDistribution.getEpiInventory()); vaccinationCoverageService.saveChildCoverage(facilityDistribution.getChildCoverage()); vaccinationCoverageService.saveAdultCoverage(facilityDistribution.getAdultCoverage()); return facilityDistribution; }
FacilityDistributionService { FacilityDistribution createDistributionData(final Facility facility, Distribution distribution, List<Refrigerator> refrigerators, List<TargetGroupProduct> childrenTargetGroupProducts, List<TargetGroupProduct> adultTargetGroupProducts, List<ProductVial> childProductVials, List<ProductVial> adultProductVials) { List<RefrigeratorReading> refrigeratorReadings = getRefrigeratorReadings(facility.getId(), refrigerators); FacilityVisit facilityVisit = new FacilityVisit(facility, distribution); facilityVisitService.save(facilityVisit); FacilityDistribution facilityDistribution = new FacilityDistribution(facilityVisit, facility, distribution, refrigeratorReadings, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials); epiUseService.save(facilityDistribution.getEpiUse()); epiInventoryService.save(facilityDistribution.getEpiInventory()); vaccinationCoverageService.saveChildCoverage(facilityDistribution.getChildCoverage()); vaccinationCoverageService.saveAdultCoverage(facilityDistribution.getAdultCoverage()); return facilityDistribution; } }
FacilityDistributionService { FacilityDistribution createDistributionData(final Facility facility, Distribution distribution, List<Refrigerator> refrigerators, List<TargetGroupProduct> childrenTargetGroupProducts, List<TargetGroupProduct> adultTargetGroupProducts, List<ProductVial> childProductVials, List<ProductVial> adultProductVials) { List<RefrigeratorReading> refrigeratorReadings = getRefrigeratorReadings(facility.getId(), refrigerators); FacilityVisit facilityVisit = new FacilityVisit(facility, distribution); facilityVisitService.save(facilityVisit); FacilityDistribution facilityDistribution = new FacilityDistribution(facilityVisit, facility, distribution, refrigeratorReadings, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials); epiUseService.save(facilityDistribution.getEpiUse()); epiInventoryService.save(facilityDistribution.getEpiInventory()); vaccinationCoverageService.saveChildCoverage(facilityDistribution.getChildCoverage()); vaccinationCoverageService.saveAdultCoverage(facilityDistribution.getAdultCoverage()); return facilityDistribution; }  }
FacilityDistributionService { FacilityDistribution createDistributionData(final Facility facility, Distribution distribution, List<Refrigerator> refrigerators, List<TargetGroupProduct> childrenTargetGroupProducts, List<TargetGroupProduct> adultTargetGroupProducts, List<ProductVial> childProductVials, List<ProductVial> adultProductVials) { List<RefrigeratorReading> refrigeratorReadings = getRefrigeratorReadings(facility.getId(), refrigerators); FacilityVisit facilityVisit = new FacilityVisit(facility, distribution); facilityVisitService.save(facilityVisit); FacilityDistribution facilityDistribution = new FacilityDistribution(facilityVisit, facility, distribution, refrigeratorReadings, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials); epiUseService.save(facilityDistribution.getEpiUse()); epiInventoryService.save(facilityDistribution.getEpiInventory()); vaccinationCoverageService.saveChildCoverage(facilityDistribution.getChildCoverage()); vaccinationCoverageService.saveAdultCoverage(facilityDistribution.getAdultCoverage()); return facilityDistribution; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution); }
FacilityDistributionService { FacilityDistribution createDistributionData(final Facility facility, Distribution distribution, List<Refrigerator> refrigerators, List<TargetGroupProduct> childrenTargetGroupProducts, List<TargetGroupProduct> adultTargetGroupProducts, List<ProductVial> childProductVials, List<ProductVial> adultProductVials) { List<RefrigeratorReading> refrigeratorReadings = getRefrigeratorReadings(facility.getId(), refrigerators); FacilityVisit facilityVisit = new FacilityVisit(facility, distribution); facilityVisitService.save(facilityVisit); FacilityDistribution facilityDistribution = new FacilityDistribution(facilityVisit, facility, distribution, refrigeratorReadings, childrenTargetGroupProducts, adultTargetGroupProducts, childProductVials, adultProductVials); epiUseService.save(facilityDistribution.getEpiUse()); epiInventoryService.save(facilityDistribution.getEpiInventory()); vaccinationCoverageService.saveChildCoverage(facilityDistribution.getChildCoverage()); vaccinationCoverageService.saveAdultCoverage(facilityDistribution.getAdultCoverage()); return facilityDistribution; }  Map<Long, FacilityDistribution> createFor(Distribution distribution); FacilityDistribution save(FacilityDistribution facilityDistribution); FacilityDistribution setSynced(FacilityDistribution facilityDistribution); Map<Long, FacilityDistribution> get(Distribution distribution);  }