### Question:
HouseholdFactory { void completeHouseholdsWithChildren(List<Household> households, List<Person> knownChildren) { Log.info("Adding all known children to households"); Log.debug("Total known Children from data: " + knownChildren.size()); knownChildren.sort(new AgeRange.AgeComparator().reversed()); List<Household> parentHhs = households.stream() .filter(h -> h.getPrimaryFamilyType() == FamilyType.ONE_PARENT || h.getPrimaryFamilyType() == FamilyType.COUPLE_WITH_CHILDREN) .sorted(Comparator.comparing(Household::getPrimaryFamily, new AgeRange.YoungestParentAgeComparator().reversed())) .collect(Collectors.toList()); Log.debug("All: Eligible households: " + parentHhs.size()); Log.debug("All: Slots to fill: " + parentHhs.stream().mapToInt(h -> h.getExpectedSize() - h.getCurrentSize()).sum()); Iterator<Person> childItr = knownChildren.iterator(); int updated = 0, completed = 0; while (childItr.hasNext()) { Person child = childItr.next(); int hhIndex = selectHouseholdWithSuitablePrimaryFamilyForChild(child, parentHhs); if (hhIndex >= 0) { Family pf = parentHhs.get(hhIndex).getPrimaryFamily(); try { pf.addMember(child); } catch (Error er) { er.printStackTrace(); Family current = parentHhs.stream() .map(Household::getFamilies) .flatMap(List::stream) .filter(f -> f.getID().equals(child.getFamilyID())) .collect(Collectors.toList()) .get(0); Log.error("Problematic family: " + current.toString()); } childItr.remove(); updated++; if (parentHhs.get(hhIndex).getExpectedSize() == parentHhs.get(hhIndex).getCurrentSize()) { completed++; parentHhs.remove(hhIndex); } } } Log.debug("Children with no suitable primary family in any eligible household: " + knownChildren.size()); childItr = knownChildren.iterator(); while (childItr.hasNext()) { Person child = childItr.next(); for (Household h : parentHhs) { Family suitableFamily = selectSuitableNonPrimaryFamilyForChild(child, h); if (suitableFamily != null) { suitableFamily.addMember(child); childItr.remove(); updated++; if (h.getExpectedSize() == h.getCurrentSize()) { completed++; } } } } Log.debug("Children with no suitable non-primary families in any eligible household: " + knownChildren.size()); Log.debug("Updated households: " + updated); Log.debug("Completed households: " + completed); } HouseholdFactory(List<HhRecord> hhRecords, Random random, ExtrasHandler extrasHandler);   }### Answer:
@Test public void testCompleteHouseholdsWithChildren() { setup(); hf.addNonPrimaryFamiliesToHouseholds(households, couples, oneParentFamilies, children, relatives, marriedMales, marriedFemales, loneParents, 0.2, null, ff); int startingChildCount = children.size(); int startingLoneParents = loneParents.size(); hf.completeHouseholdsWithChildren(households, children); Assert.assertEquals("One children from children list was assigned to One Parent primary family household", startingChildCount - 1, children.size()); Assert.assertEquals("Lone parents should not be assigned to families", startingLoneParents, loneParents.size()); }