### Question:
ServiceDependencyResolver { private SetMultimap<String, String> minimizeDependencies(Function<Service, Set<String>> getDependencies) { SetMultimap<String, String> minimized = HashMultimap.create(); for (Service service : clusterServices.values()) { Set<String> givenDependencies = getDependencies.apply(service); Set<String> indirectDependencies = Sets.newHashSet(); Set<String> newDependencies = Sets.newHashSet(givenDependencies); while (!newDependencies.isEmpty()) { Set<String> newIndirectDependencies = Sets.newHashSet(); for (String dependentServiceName : newDependencies) { if (clusterServices.containsKey(dependentServiceName)) { Service dependentService = clusterServices.get(dependentServiceName); Set<String> dependenciesOfDependency = getDependencies.apply(dependentService); newIndirectDependencies.addAll(Sets.difference(dependenciesOfDependency, indirectDependencies)); } } indirectDependencies.addAll(newIndirectDependencies); newDependencies = newIndirectDependencies; } minimized.putAll(service.getName(), Sets.difference(givenDependencies, indirectDependencies)); } return minimized; } ServiceDependencyResolver(Actions actions, Map<String, Service> clusterServices); Set<ActionOnService> getDirectDependentActions(String service, ProvisionerAction action); boolean runtimeDependsOn(String service1, String service2);  }### Answer:
@Test public void testMinimizeDependencies() { Service base = Service.builder().setName("base").build(); Service s1 = Service.builder() .setName("s1") .setDependencies(ServiceDependencies.runtimeRequires("base")) .build(); Service s2 = Service.builder() .setName("s2") .setDependencies(ServiceDependencies.runtimeRequires("base", "s1")) .build(); Service s3 = Service.builder() .setName("s3") .setDependencies(ServiceDependencies.runtimeRequires("base", "s1", "s2")) .build(); Service s4 = Service.builder() .setName("s4") .setDependencies(ServiceDependencies.runtimeRequires("base")) .build(); Service s5 = Service.builder() .setName("s5") .setDependencies(ServiceDependencies.runtimeRequires("base", "s1", "s2", "s3", "s4")) .build(); Map<String, Service> serviceMap = Maps.newHashMap(); serviceMap.put(base.getName(), base); serviceMap.put(s1.getName(), s1); serviceMap.put(s2.getName(), s2); serviceMap.put(s3.getName(), s3); serviceMap.put(s4.getName(), s4); serviceMap.put(s5.getName(), s5); SetMultimap<String, String> expected = HashMultimap.create(); expected.put("s1", "base"); expected.put("s2", "s1"); expected.put("s3", "s2"); expected.put("s4", "base"); expected.put("s5", "s3"); expected.put("s5", "s4"); ServiceDependencyResolver resolver = new ServiceDependencyResolver(Actions.getInstance(), serviceMap); SetMultimap<String, String> actual = resolver.getRuntimeServiceDependencies(); Assert.assertEquals(expected, actual); Assert.assertTrue(actual.get("base").isEmpty()); }