### Question:
DependencyTreeFormatter { static String formatDependencyPaths(List<DependencyPath> dependencyPaths) { DependencyPath firstPath = dependencyPaths.get(0); Artifact rootArtifact = firstPath.get(0); checkArgument( dependencyPaths.stream().allMatch(path -> Objects.equals(path.get(0), rootArtifact)), "all dependency paths should have the same root"); StringBuilder stringBuilder = new StringBuilder(); ListMultimap<DependencyPath, DependencyPath> tree = buildDependencyPathTree(dependencyPaths); formatDependencyPathTree(stringBuilder, tree, new DependencyPath(rootArtifact), 1); return stringBuilder.toString(); }  static ListMultimap<DependencyPath, DependencyPath> buildDependencyPathTree(
      Collection<DependencyPath> dependencyPaths);  }### Answer:
@Test public void testDependencyTree() { List<DependencyPath> dependencyPathList = new ArrayList<>(); DependencyPath path2 = new DependencyPath(new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0")) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-core:jar:1.15.0"), "compile", false)); dependencyPathList.add(path2); DependencyPath path1 = new DependencyPath(new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0")); dependencyPathList.add(path1); DependencyPath path3 = new DependencyPath(new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0")) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-core:jar:1.15.0"), "compile", false)) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-context:jar:1.15.0"), "compile", false)); dependencyPathList.add(path3); DependencyPath path4 = new DependencyPath(new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0")) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-core:jar:1.15.0"), "compile", false)) .append( new Dependency( new DefaultArtifact("com.google.code.gson:gson:jar:2.7"), "compile", false)); dependencyPathList.add(path4); String actualTreeOutput = DependencyTreeFormatter.formatDependencyPaths(dependencyPathList); String expectedTreeOutput = " io.grpc:grpc-auth:jar:1.15.0\n" + " io.grpc:grpc-core:jar:1.15.0\n" + " io.grpc:grpc-context:jar:1.15.0\n" + " com.google.code.gson:gson:jar:2.7\n"; Assert.assertEquals( "The dependency should be output as tree with indentation", expectedTreeOutput, actualTreeOutput); }
@Test public void testDependencyTree_scopeAndOptionalFlag() { List<DependencyPath> dependencyPathList = new ArrayList<>(); DependencyPath path1 = new DependencyPath(null) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0"), "compile", true)); dependencyPathList.add(path1); DependencyPath path2 = new DependencyPath(null) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-auth:jar:1.15.0"), "compile", true)) .append( new Dependency( new DefaultArtifact("io.grpc:grpc-core:jar:1.15.0"), "provided", false)); dependencyPathList.add(path2); String actualTreeOutput = DependencyTreeFormatter.formatDependencyPaths(dependencyPathList); String expectedTreeOutput = " io.grpc:grpc-auth:jar:1.15.0\n" + " io.grpc:grpc-core:jar:1.15.0\n"; Assert.assertEquals(expectedTreeOutput, actualTreeOutput); }