### Question:
ConfigurationRecommendationCommand extends StackAdvisorCommand<RecommendationResponse> { protected Set<HostGroup> processHostGroups(StackAdvisorRequest request) { Set<HostGroup> resultSet = new HashSet<>(); for (Map.Entry<String, Set<String>> componentHost : request.getHostComponents().entrySet()) { String hostGroupName = componentHost.getKey(); Set<String> components = componentHost.getValue(); if (hostGroupName != null && components != null) { HostGroup hostGroup = new HostGroup(); Set<Map<String, String>> componentsSet = new HashSet<>(); for (String component : components) { Map<String, String> componentMap = new HashMap<>(); componentMap.put("name", component); componentsSet.add(componentMap); } hostGroup.setComponents(componentsSet); hostGroup.setName(hostGroupName); resultSet.add(hostGroup); } } return resultSet; } ConfigurationRecommendationCommand(StackAdvisorCommandType commandType, File recommendationsDir,
                                            String recommendationsArtifactsLifetime,
                                            ServiceInfo.ServiceAdvisorType serviceAdvisorType,
                                            int requestId,
                                            StackAdvisorRunner saRunner,
                                            AmbariMetaInfo metaInfo,
                                            AmbariServerConfigurationHandler ambariServerConfigurationHandler); @Override StackAdvisorCommandType getCommandType();  }### Answer:
@Test public void testProcessHostGroups() throws Exception { StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class); File file = mock(File.class); AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class); ConfigurationRecommendationCommand command = new ConfigurationRecommendationCommand(StackAdvisorCommandType.RECOMMEND_CONFIGURATIONS, file, "1w", ServiceInfo.ServiceAdvisorType.PYTHON, 1, saRunner, metaInfo, null); StackAdvisorRequest request = mock(StackAdvisorRequest.class); Map<String, Set<String>> componentHostGroupMap = new HashMap<>(); Set<String> components1 = new HashSet<>(); components1.add("component1"); components1.add("component4"); components1.add("component5"); componentHostGroupMap.put("group1", components1); Set<String> components2 = new HashSet<>(); components2.add("component2"); components2.add("component3"); componentHostGroupMap.put("group2", components2); doReturn(componentHostGroupMap).when(request).getHostComponents(); Set<RecommendationResponse.HostGroup> hostGroups = command.processHostGroups(request); assertNotNull(hostGroups); assertEquals(2, hostGroups.size()); Map<String, RecommendationResponse.HostGroup> hostGroupMap = new HashMap<>(); for (RecommendationResponse.HostGroup hostGroup : hostGroups) { hostGroupMap.put(hostGroup.getName(), hostGroup); } RecommendationResponse.HostGroup hostGroup1 = hostGroupMap.get("group1"); assertNotNull(hostGroup1); Set<Map<String, String>> host1Components = hostGroup1.getComponents(); assertNotNull(host1Components); assertEquals(3, host1Components.size()); Set<String> componentNames1 = new HashSet<>(); for (Map<String, String> host1Component : host1Components) { assertNotNull(host1Component); assertEquals(1, host1Component.size()); String componentName = host1Component.get("name"); assertNotNull(componentName); componentNames1.add(componentName); } assertEquals(3, componentNames1.size()); assertTrue(componentNames1.contains("component1")); assertTrue(componentNames1.contains("component4")); assertTrue(componentNames1.contains("component5")); RecommendationResponse.HostGroup hostGroup2 = hostGroupMap.get("group2"); assertNotNull(hostGroup2); Set<Map<String, String>> host2Components = hostGroup2.getComponents(); assertNotNull(host2Components); assertEquals(2, host2Components.size()); Set<String> componentNames2 = new HashSet<>(); for (Map<String, String> host2Component : host2Components) { assertNotNull(host2Component); assertEquals(1, host2Component.size()); String componentName = host2Component.get("name"); assertNotNull(componentName); componentNames2.add(componentName); } assertEquals(2, componentNames2.size()); assertTrue(componentNames2.contains("component2")); assertTrue(componentNames2.contains("component3")); }