### Question:
PartitionUtil { public static void greedyPartitionFailuresOnSameHost(Collection<TestTime> testTimes, Set<TestContainer> testContainers) { Map<String, TestContainer> hostToContainerMap = testContainers.stream() .collect(Collectors.toMap(TestContainer::getHostName, Function.identity())); List<TestTime> unassignedTests = new ArrayList<>(); for (TestTime test : testTimes) { if (test.isFailed()) { if (hostToContainerMap.containsKey(test.getHostName())) { hostToContainerMap.get(test.getHostName()).addTestTime(test); } else { unassignedTests.add(test); } } else { unassignedTests.add(test); } } greedyPartition(unassignedTests, testContainers); }  static void greedyPartitionFailuresOnSameHost(Collection<TestTime> testTimes, Set<TestContainer> testContainers); static void greedyPartition(Collection<TestTime> testTimes, Set<TestContainer> testContainers);  }### Answer:
@Test public void greedyPartitionFailuresOnSameHost() { Collection<TestTime> host1Tests = generateTests(10, "host1"); host1Tests.forEach(t -> t.setFailed(true)); Collection<TestTime> host2Tests = generateTests(10, "host2"); host2Tests.forEach(t -> t.setFailed(true)); Set<TestContainer> containers = createTestContainers(2); List<TestTime> allTests = new ArrayList<>(); allTests.addAll(host1Tests); allTests.addAll(host2Tests); PartitionUtil.greedyPartitionFailuresOnSameHost(allTests, containers); for (TestContainer container : containers) { Collection<TestTime> expected = container.getHostName().equals("host1") ? host1Tests : host2Tests; assertEquals(expected, new HashSet<>(container.getTestTimes())); } }