### Question:
DescriptorVisitorImpl implements DescriptorVisitor { @Override public <T> T visit(Object rootObject, NodeProcessor<T> processor) { DescriptorPathImpl root = new DescriptorPathImpl(); visit(rootObject, root, processor); return processor.getResult(); }  @Override T visit(Object rootObject, NodeProcessor<T> processor);  }### Answer:
@Test public void testVisitNamed() { NamedSubDescriptor sub = new NamedSubDescriptor("foo"); final Set<String> beforePaths = Sets.newHashSet(); visitor.visit(sub, new AbstractNodeProcessor<Object>() { @Override public void beforeNode(Object obj, DescriptorPath path) { beforePaths.add(path.toString()); } }); assertEquals(ImmutableSet.of("foo", "foo.name"), beforePaths); }
@Test public void testVisitReturn() { String returnStr = visitor.visit(new Descriptor(), new AbstractNodeProcessor<String>() { @Override public String getResult() { return "resultString"; } }); assertEquals("resultString", returnStr); }
@Test public void testNestedObjects() { NamedSubDescriptor named1 = new NamedSubDescriptor("named1"); NamedSubDescriptor named2 = new NamedSubDescriptor("named2"); SubDescriptor sub1 = new SubDescriptor("sub", ImmutableSet.<NamedSubDescriptor>of()); SubDescriptor subWithChildren = new SubDescriptor("sub2", ImmutableSet.of(named2)); Descriptor descriptor = new Descriptor(); descriptor.sub = subWithChildren; descriptor.namedSub = named1; descriptor.set = ImmutableSet.of(sub1, subWithChildren); final Set<String> beforePaths = Sets.newHashSet(); visitor.visit(descriptor, new AbstractNodeProcessor<Object>() { @Override public void beforeNode(Object obj, DescriptorPath path) { beforePaths.add(path.toString()); } }); assertEquals(ImmutableSet.of("Descriptor.sub", "Descriptor.sub.SubDescriptor", "Descriptor.sub.SubDescriptor.name", "Descriptor.sub.SubDescriptor.set", "Descriptor.sub.SubDescriptor.set.named2", "Descriptor.sub.SubDescriptor.set.named2.name", "Descriptor.namedSub", "Descriptor.namedSub.named1", "Descriptor.namedSub.named1.name", "Descriptor.set", "Descriptor"), beforePaths); }
@Test public void testVisit() { NamedSubDescriptor childSub = new NamedSubDescriptor("child"); SubDescriptor sub = new SubDescriptor("foo", ImmutableSet.of(childSub)); final Set<String> beforePaths = Sets.newHashSet(); final Set<String> afterPaths = Sets.newHashSet(); visitor.visit(sub, new AbstractNodeProcessor<Object>() { @Override public void beforeNode(Object obj, DescriptorPath path) { beforePaths.add(path.toString()); } @Override public void afterNode(Object obj, DescriptorPath oldPath) { afterPaths.add(oldPath.toString()); } }); assertEquals(ImmutableSet.of("SubDescriptor", "SubDescriptor.name", "SubDescriptor.set", "SubDescriptor.set.child", "SubDescriptor.set.child.name"), beforePaths); assertEquals(ImmutableSet.of("SubDescriptor", "SubDescriptor.name", "SubDescriptor.set", "SubDescriptor.set.child", "SubDescriptor.set.child.name"), afterPaths); }