### Question:
AllHostPublicDnsEntryService extends BaseDnsEntryService { @Override protected Map<String, List<String>> getComponentLocation(Stack stack) { InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); Function<InstanceGroup, List<String>> notTerminatedAndPrimaryGatewayInstances = ig -> ig.getNotTerminatedInstanceMetaDataSet() .stream() .filter(im -> !im.getDiscoveryFQDN().equals(primaryGatewayInstance.getDiscoveryFQDN())) .map(InstanceMetaData::getDiscoveryFQDN) .collect(Collectors.toList()); return stack.getInstanceGroups() .stream() .filter(ig -> !(ig.getNotTerminatedInstanceMetaDataSet().contains(primaryGatewayInstance) && ig.getNodeCount() == GROUP_WITH_SINGLE_NODE)) .collect(Collectors.toMap(InstanceGroup::getGroupName, notTerminatedAndPrimaryGatewayInstances)); }    }### Answer:
@Test void getComponentLocationWhenPrimaryGatewayIsTheOnlyNodeWithinGroup() { Stack stack = TestUtil.stack(); Map<String, List<String>> result = underTest.getComponentLocation(stack); InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); Assertions.assertFalse(result.containsKey(primaryGatewayInstance.getInstanceGroupName()), "Result should not contain primary gateway's group name"); Assertions.assertFalse(resultContainsInstanceMetadata(primaryGatewayInstance, result), "Result should not contain primary gateway's instance metadata"); }
@Test void getComponentLocationWhenPrimaryGatewayIsNotTheOnlyNodeWithinGatewayHostGroup() { Stack stack = TestUtil.stack(); InstanceMetaData primaryGatewayInstance = stack.getPrimaryGatewayInstance(); InstanceGroup gatewayInstanceGroup = primaryGatewayInstance.getInstanceGroup(); InstanceMetaData otherGatewayInstanceMetadata = new InstanceMetaData(); otherGatewayInstanceMetadata.setDiscoveryFQDN("something.new"); otherGatewayInstanceMetadata.setInstanceGroup(gatewayInstanceGroup); otherGatewayInstanceMetadata.setInstanceStatus(InstanceStatus.SERVICES_RUNNING); Set<InstanceMetaData> updatedIM = gatewayInstanceGroup.getNotTerminatedInstanceMetaDataSet(); updatedIM.add(otherGatewayInstanceMetadata); gatewayInstanceGroup.replaceInstanceMetadata(updatedIM); Map<String, List<String>> result = underTest.getComponentLocation(stack); Assertions.assertTrue(result.containsKey(primaryGatewayInstance.getInstanceGroupName()), "Result should contain primary gateway's group name"); Assertions.assertTrue(resultContainsInstanceMetadata(otherGatewayInstanceMetadata, result), "Result should contain other gateway's instance metadata"); Assertions.assertFalse(resultContainsInstanceMetadata(primaryGatewayInstance, result), "Result should not contain primary gateway's instance metadata"); }