### Question:
OrphanedGroupsByRegionId implements Function<Set<? extends NodeMetadata>, Multimap<String, String>> { public Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes) { Iterable<? extends NodeMetadata> nodesWithGroup = filter(deadNodes, NodePredicates.hasGroup()); Set<RegionAndName> regionAndGroupNames = ImmutableSet.copyOf(filter(transform(nodesWithGroup, new Function<NodeMetadata, RegionAndName>() { @Override public RegionAndName apply(NodeMetadata input) { String regionId = input.getLocation().getScope() == LocationScope.HOST ? input.getLocation() .getParent().getId() : input.getLocation().getId(); return RegionAndName.fromRegionAndName(regionId, input.getGroup()); } }), allNodesInGroupTerminated)); Multimap<String, String> regionToRegionAndGroupNames = Multimaps.transformValues(Multimaps.index(regionAndGroupNames, RegionAndName.REGION_FUNCTION), RegionAndName.NAME_FUNCTION); return regionToRegionAndGroupNames; } @Inject protected  OrphanedGroupsByRegionId(ComputeService computeService); @VisibleForTesting  OrphanedGroupsByRegionId(Predicate<RegionAndName> allNodesInGroupTerminated); Multimap<String, String> apply(Set<? extends NodeMetadata> deadNodes);  }### Answer:
@Test public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysTrue()).apply(set), ImmutableMultimap .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build()); }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysFalse()).apply(set), ImmutableMultimap .<String, String> of()); }