### Question:
RootServiceResponseFactory extends
    AbstractRootServiceResponseFactory { @Override public Set<RootServiceComponentResponse> getRootServiceComponents( RootServiceComponentRequest request) throws ObjectNotFoundException { Set<RootServiceComponentResponse> response = new HashSet<>(); String serviceName = request.getServiceName(); String componentName = request.getComponentName(); RootService service; try { service = RootService.valueOf(serviceName); } catch (IllegalArgumentException ex) { throw new ObjectNotFoundException("Root service name: " + serviceName); } catch (NullPointerException np) { throw new ObjectNotFoundException("Root service name: null"); } if (componentName != null) { RootComponent component; try { component = RootComponent.valueOf(componentName); if (!ArrayUtils.contains(service.getComponents(), component)) throw new ObjectNotFoundException("No component name: " + componentName + "in service: " + serviceName); } catch (IllegalArgumentException ex) { throw new ObjectNotFoundException("Component name: " + componentName); } response = Collections.singleton(new RootServiceComponentResponse(serviceName, component.toString(), getComponentVersion(componentName, null), getComponentProperties(componentName))); } else { for (RootComponent component: service.getComponents()) response.add(new RootServiceComponentResponse(serviceName, component.toString(), getComponentVersion(component.name(), null), getComponentProperties(component.name()))); } return response; }  @Override Set<RootServiceResponse> getRootServices(RootServiceRequest request); @Override Set<RootServiceComponentResponse> getRootServiceComponents(
      RootServiceComponentRequest request); @Override Set<RootServiceHostComponentResponse> getRootServiceHostComponent(RootServiceHostComponentRequest request, Set<HostResponse> hosts); static final String NOT_APPLICABLE; }### Answer:
@Test(expected = ObjectNotFoundException.class) public void getThrowsForNullServiceNameNullComponentName() throws Exception { RootServiceComponentRequest request = new RootServiceComponentRequest(null, null); responseFactory.getRootServiceComponents(request); }
@Test(expected = ObjectNotFoundException.class) public void getThrowsForNullServiceNameValidComponentName() throws Exception { RootServiceComponentRequest request = new RootServiceComponentRequest(null, AMBARI_SERVER.name()); responseFactory.getRootServiceComponents(request); }
@Test public void getReturnsAllComponentsForValidServiceNameNullComponentName() throws Exception { RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), null); Set<RootServiceComponentResponse> rootServiceComponents = responseFactory.getRootServiceComponents(request); assertEquals(AMBARI.getComponents().length, rootServiceComponents.size()); for (int i = 0; i < AMBARI.getComponents().length; i++) { RootComponent component = AMBARI.getComponents()[i]; if (component.name().equals(AMBARI_SERVER.name())) { for (RootServiceComponentResponse response : rootServiceComponents) { if (response.getComponentName().equals(AMBARI_SERVER.name())) { verifyResponseForAmbariServer(response); } } } else { assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse( AMBARI.name(), component.name(), RootServiceResponseFactory.NOT_APPLICABLE, Collections.emptyMap()))); } } }
@Test public void getReturnsSingleComponentForValidServiceAndComponentName() throws Exception { RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), AMBARI_SERVER.name()); Set<RootServiceComponentResponse> rootServiceComponents = responseFactory.getRootServiceComponents(request); assertEquals(1, rootServiceComponents.size()); for (RootServiceComponentResponse response : rootServiceComponents) { verifyResponseForAmbariServer(response); } }
@Test(expected = ObjectNotFoundException.class) public void getThrowsForNonexistentComponent() throws Exception { RootServiceComponentRequest request = new RootServiceComponentRequest(AMBARI.name(), "XXX"); responseFactory.getRootServiceComponents(request); }