### Question:
HouseholdFactory { private void assignOneParentUnitsAsNonPrimaryFamilies(List<Household> households, List<Family> basicUnits) { Log.info("Adding " + FamilyType.ONE_PARENT + " as non primary"); Log.debug(FamilyType.ONE_PARENT + ": available family units: " + basicUnits.size()); List<Household> eligibleHhs = households.stream() .filter(h -> (FamilyType.ONE_PARENT == h.getPrimaryFamilyType() || FamilyType.COUPLE_WITH_CHILDREN == h.getPrimaryFamilyType()) && (h.getExpectedFamilyCount() > h.getCurrentFamilyCount()) && (h.getExpectedSize() - h.getCurrentSize() >= FamilyType.ONE_PARENT.basicSize())) .collect(Collectors.toList()); Log.debug(FamilyType.ONE_PARENT + ": total eligible households: " + eligibleHhs.size()); int added = 0, completed = 0; while (!basicUnits.isEmpty() && !eligibleHhs.isEmpty()) { int randIndex = random.nextInt(eligibleHhs.size()); Family f = basicUnits.remove(0); f.setType(FamilyType.ONE_PARENT); eligibleHhs.get(randIndex).addFamily(f); if (eligibleHhs.get(randIndex).getExpectedFamilyCount() == eligibleHhs.get(randIndex) .getCurrentFamilyCount()) { eligibleHhs.remove(randIndex); completed++; } added++; } Log.debug(FamilyType.ONE_PARENT + ": updated households: " + added); Log.debug(FamilyType.ONE_PARENT + ": family count completed households: " + completed); Log.debug(FamilyType.ONE_PARENT + ": remaining eligible households: " + eligibleHhs.stream() .filter(h -> h.getExpectedFamilyCount() > h .getCurrentFamilyCount()) .count()); } HouseholdFactory(List<HhRecord> hhRecords, Random random, ExtrasHandler extrasHandler);   }### Answer:
@Test public void testAssignOneParentUnitsAsNonPrimaryFamilies() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { setup(); Assert.assertTrue("One parent families are not empty", !oneParentFamilies.isEmpty()); int startOneParentFamiliesCount = oneParentFamilies.size(); int startNonPrimarySlots = households.parallelStream().mapToInt(h -> h.getExpectedFamilyCount() - h.getCurrentFamilyCount()).sum(); Method method = HouseholdFactory.class.getDeclaredMethod("assignOneParentUnitsAsNonPrimaryFamilies", List.class, List.class); method.setAccessible(true); method.invoke(hf, households, oneParentFamilies); Assert.assertTrue("One parent families were assigned as non-primary families", startOneParentFamiliesCount > oneParentFamilies.size()); int usedOneParentFamilies = startOneParentFamiliesCount - oneParentFamilies.size(); int endNonPrimarySlots = households.parallelStream().mapToInt(h -> h.getExpectedFamilyCount() - h.getCurrentFamilyCount()).sum(); Assert.assertEquals("Only One Parent families are used as non-primary families", (startNonPrimarySlots - endNonPrimarySlots), usedOneParentFamilies); }