### Question:
DependencyCollector { public Set<String> collect(JavaFileOnClasspath<?> javaFile, ClassLoader classLoader) { return genericCollect(javaFile, classLoader); } DependencyCollector();  DependencyCollector(DependencyCollector nextCollector); Set<String> collect(JavaFileOnClasspath<?> javaFile, ClassLoader classLoader); Set<String> collect(JavaFileWithSource<?> javaFile, ClassLoader classLoader);  }### Answer:
@Test public void testChainability() { final String firstClassName = Integer.class.getName(); final String secondClassName = Float.class.getName(); final String thirdClassName = Byte.class.getName(); DependencyCollector third = new DependencyCollector() { @Override protected Set<String> collectInternal(JavaFile<?> javaFile, ClassLoader classLoader) { return Sets.newHashSet(thirdClassName); } }; DependencyCollector second = new DependencyCollector(third) { @Override protected Set<String> collectInternal(JavaFile<?> javaFile, ClassLoader classLoader) { return Sets.newHashSet(secondClassName); } }; DependencyCollector first = new DependencyCollector(second) { @Override protected Set<String> collectInternal(JavaFile<?> javaFile, ClassLoader classLoader) { return Sets.newHashSet(firstClassName); } }; Set<String> dependencies = first.collect(new JavaFileOnClasspath<>(String.class), getCurrentClassLoader()); assertTrue(dependencies.contains(firstClassName)); assertTrue(dependencies.contains(secondClassName)); assertTrue(dependencies.contains(thirdClassName)); }