### Question:
ResourceTreeVisitor implements Visitor { @Override public ResourceComponent visit() { ResourceComponent rootDirectory = new Directory(); for (Resource resource : resourceList) { if (rootNode(resource)){ ResourceComponent tempResourceComponent = getResourceComponent(resource); rootDirectory.add(tempResourceComponent); tempResourceComponent.setChildren(setChildren(tempResourceComponent.getId(),resourceList)); } } return rootDirectory; } ResourceTreeVisitor();  ResourceTreeVisitor(List<Resource> resourceList); @Override ResourceComponent visit(); static List<ResourceComponent> setChildren(int id, List<Resource> list ); boolean rootNode(Resource resource);  }### Answer:
@Test public void visit() throws Exception { List<Resource> resourceList = new ArrayList<>(); Resource resource1 = new Resource(3,-1,"b","/b",true); Resource resource2 = new Resource(4,2,"a1.txt","/a/a1.txt",false); Resource resource3 = new Resource(5,3,"b1.txt","/b/b1.txt",false); Resource resource4 = new Resource(6,3,"b2.jar","/b/b2.jar",false); Resource resource5 = new Resource(7,-1,"b2","/b2",true); Resource resource6 = new Resource(8,-1,"b2","/b/b2",true); Resource resource7 = new Resource(9,8,"c2.jar","/b/b2/c2.jar",false); resourceList.add(resource1); resourceList.add(resource2); resourceList.add(resource3); resourceList.add(resource4); resourceList.add(resource5); resourceList.add(resource6); resourceList.add(resource7); ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(resourceList); ResourceComponent resourceComponent = resourceTreeVisitor.visit(); Assert.assertNotNull(resourceComponent.getChildren()); }