### Question:
HouseholdFactory { void completeHouseholdsWithRelatives(List<Household> households, List<Person> relatives, FamilyHouseholdType familyHouseholdType) { Log.info("Fill " + ((familyHouseholdType == null) ? "All" : familyHouseholdType) + " households with relatives"); Log.debug("Start remaining relatives: " + relatives.size()); Log.debug("Start remaining extras: " + extrasHandler.remainingExtras()); Collections.shuffle(relatives, random); List<Household> availableHhs = households.stream() .filter(hh -> (hh.getFamilyHouseholdType() == familyHouseholdType || familyHouseholdType == null) && (hh.getExpectedSize() > hh.getCurrentSize())) .collect(Collectors.toList()); Log.debug((familyHouseholdType != null ? familyHouseholdType.name() : "All") + ": Eligible households: " + availableHhs.size()); Log.debug((familyHouseholdType != null ? familyHouseholdType.name() : "All") + ": Slots to fill: " + availableHhs.stream() .mapToInt(h -> h .getExpectedSize() - h .getCurrentSize()) .sum()); int formed = 0; for (Household h : availableHhs) { int diff = h.getExpectedSize() - h.getCurrentSize(); if (diff > 0) { Family f = h.getPrimaryFamily(); if (relatives.size() >= diff) { f.addMembers(relatives.subList(0, diff)); relatives.subList(0, diff).clear(); } else { int rels = relatives.size(); f.addMembers(relatives); relatives.clear(); f.addMembers(extrasHandler.getPersonsFromExtras(RelationshipStatus.RELATIVE, null, null, diff - rels)); } formed++; } } Log.info((familyHouseholdType != null ? familyHouseholdType.name() : "All") + ": updated households: " + formed); Log.debug("End remaining relatives: " + relatives.size()); Log.debug("End remaining extras: " + extrasHandler.remainingExtras()); } HouseholdFactory(List<HhRecord> hhRecords, Random random, ExtrasHandler extrasHandler);   }### Answer:
@Test public void testcompleteHouseholdsWithRelatives(){ setup(); hf.addNonPrimaryFamiliesToHouseholds(households, couples, oneParentFamilies, children, relatives, marriedMales, marriedFemales, loneParents, 0.2, null, ff); hf.completeHouseholdsWithChildren(households, children); hf.addExtrasAsChildrenAndRelatives(households, indRecords, marriedMales, marriedFemales, loneParents, children); Assert.assertTrue("There are relatives remaining", !relatives.isEmpty()); hf.completeHouseholdsWithRelatives(households, relatives, null); Assert.assertTrue("All households are complete", households.parallelStream().allMatch(h -> h.validate())); Assert.assertTrue("All Relatives were used", relatives.isEmpty()); }