### Question:
HeartBeatHandler { public ComponentsResponse handleComponents(String clusterName) throws AmbariException { ComponentsResponse response = new ComponentsResponse(); Cluster cluster = clusterFsm.getCluster(clusterName); Map<String, Map<String, String>> componentsMap = new HashMap<>(); for (org.apache.ambari.server.state.Service service : cluster.getServices().values()) { componentsMap.put(service.getName(), new HashMap<>()); for (ServiceComponent component : service.getServiceComponents().values()) { StackId stackId = component.getDesiredStackId(); ComponentInfo componentInfo = ambariMetaInfo.getComponent( stackId.getStackName(), stackId.getStackVersion(), service.getName(), component.getName()); componentsMap.get(service.getName()).put(component.getName(), componentInfo.getCategory()); } } response.setClusterName(clusterName); response.setComponents(componentsMap); return response; } @Inject  HeartBeatHandler(Clusters fsm, ActionManager am,
                          Injector injector); void start(); void setHeartbeatProcessor(HeartbeatProcessor heartbeatProcessor); HeartbeatProcessor getHeartbeatProcessor(); HeartBeatResponse handleHeartBeat(HeartBeat heartbeat); void handleComponentReportStatus(List<ComponentStatus> componentStatuses, String hostname); void handleCommandReportStatus(List<CommandReport> reports, String hostname); void handleHostReportStatus(HostStatusReport hostStatusReport, String hostname); void handleComponentVersionReports(ComponentVersionReports componentVersionReports, String hostname); String getOsType(String os, String osRelease); HeartBeatResponse createRegisterCommand(); RegistrationResponse handleRegistration(Register register); ComponentsResponse handleComponents(String clusterName); void stop();  }### Answer:
@Test @Ignore public void testComponents() throws Exception { ComponentsResponse expected = new ComponentsResponse(); StackId dummyStackId = new StackId(DummyStackId); Map<String, Map<String, String>> dummyComponents = new HashMap<>(); Map<String, String> dummyCategoryMap = new HashMap<>(); dummyCategoryMap.put("NAMENODE", "MASTER"); dummyComponents.put("HDFS", dummyCategoryMap); expected.setClusterName(DummyCluster); expected.setStackName(dummyStackId.getStackName()); expected.setStackVersion(dummyStackId.getStackVersion()); expected.setComponents(dummyComponents); Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service service = EasyMock.createNiceMock(Service.class); expect(service.getName()).andReturn("HDFS").atLeastOnce(); Map<String, ServiceComponent> componentMap = new HashMap<>(); ServiceComponent nnComponent = EasyMock.createNiceMock(ServiceComponent.class); expect(nnComponent.getName()).andReturn("NAMENODE").atLeastOnce(); expect(nnComponent.getDesiredStackId()).andReturn(dummyStackId).atLeastOnce(); componentMap.put("NAMENODE", nnComponent); expect(service.getServiceComponents()).andReturn(componentMap).atLeastOnce(); ActionManager am = actionManagerTestHelper.getMockActionManager(); replay(service, nnComponent, am); cluster.addService(service); HeartBeatHandler handler = heartbeatTestHelper.getHeartBeatHandler(am); assertNotNull(handler); ComponentsResponse actual = handler.handleComponents(DummyCluster); if (log.isDebugEnabled()) { log.debug(actual.toString()); } assertEquals(expected.getClusterName(), actual.getClusterName()); assertEquals(expected.getComponents(), actual.getComponents()); }