### Question:
AmbariContext { public void registerHostWithConfigGroup(final String hostName, final ClusterTopology topology, final String groupName) { String qualifiedGroupName = getConfigurationGroupName(topology.getBlueprint().getName(), groupName); Lock configGroupLock = configGroupCreateLock.get(qualifiedGroupName); try { configGroupLock.lock(); boolean hostAdded = RetryHelper.executeWithRetry(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return addHostToExistingConfigGroups(hostName, topology, qualifiedGroupName); } }); if (!hostAdded) { createConfigGroupsAndRegisterHost(topology, groupName); } } catch (Exception e) { LOG.error("Unable to register config group for host: ", e); throw new RuntimeException("Unable to register config group for host: " + hostName); } finally { configGroupLock.unlock(); } }  boolean isClusterKerberosEnabled(long clusterId); HostRoleCommand createAmbariTask(long requestId, long stageId, String component, String host,
                                          TaskType type, boolean skipFailure); HostRoleCommand createAmbariTask(long taskId, long requestId, long stageId,
                                          String component, String host, TaskType type, boolean skipFailure); HostRoleCommand getPhysicalTask(long id); Collection<HostRoleCommand> getPhysicalTasks(Collection<Long> ids); void createAmbariResources(ClusterTopology topology, String clusterName, SecurityType securityType,
                                    String repoVersionString, Long repoVersionId); void createAmbariClusterResource(String clusterName, String stackName, String stackVersion, SecurityType securityType); void createAmbariServiceAndComponentResources(ClusterTopology topology, String clusterName,
      StackId stackId, Long repositoryVersionId); void createAmbariHostResources(long  clusterId, String hostName, Map<String, Collection<String>> components); Long getNextRequestId(); synchronized static AmbariManagementController getController(); synchronized static ClusterController getClusterController(); static void init(HostRoleCommandFactory factory); void registerHostWithConfigGroup(final String hostName, final ClusterTopology topology, final String groupName); RequestStatusResponse installHost(String hostName, String clusterName, Collection<String> skipInstallForComponents, Collection<String> dontSkipInstallForComponents, boolean skipFailure); RequestStatusResponse startHost(String hostName, String clusterName, Collection<String> installOnlyComponents, boolean skipFailure); void persistInstallStateForUI(String clusterName, String stackName, String stackVersion); List<ConfigurationRequest> createConfigurationRequests(Map<String, Object> clusterProperties); void setConfigurationOnCluster(final ClusterRequest clusterRequest); void notifyAgentsAboutConfigsChanges(String clusterName); void waitForConfigurationResolution(String clusterName, Set<String> updatedConfigTypes); boolean isTopologyResolved(long clusterId); PersistedState getPersistedTopologyState(); boolean isHostRegisteredWithCluster(long clusterId, String host); long getClusterId(String clusterName); String getClusterName(long clusterId); ConfigHelper getConfigHelper();  }### Answer:
@Test public void testRegisterHostWithConfigGroup_registerWithExistingConfigGroup() throws Exception { expect(cluster.getConfigGroups()).andReturn(configGroups).once(); expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(2L, host2)).once(); configGroup1.addHost(host1); replayAll(); context.registerHostWithConfigGroup(HOST1, topology, HOST_GROUP_1); }
@Test public void testRegisterHostWithConfigGroup_registerWithExistingConfigGroup_hostAlreadyRegistered() throws Exception { expect(cluster.getConfigGroups()).andReturn(configGroups).once(); expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(1L, host1)).once(); replayAll(); context.registerHostWithConfigGroup(HOST1, topology, HOST_GROUP_1); }