// Path: src/main/java/com/google/devtools/build/bfg/BuildozerCommandCreator.java
// static ImmutableList<String> computeBuildozerCommands(Graph<BuildRule> buildRuleDAG) {
//   ImmutableList.Builder<String> commands = ImmutableList.builder();
//   for (BuildRule buildRule : buildRuleDAG.nodes()) {
//     List<String> initialCommands = buildRule.getCreatingBuildozerCommands();
//     commands.addAll(initialCommands);
//     List<String> depsList = getDepsForBuildRule(buildRuleDAG, buildRule);
//     if (buildRule.shouldAddDeps() && !depsList.isEmpty()) {
//       commands.add(BuildozerCommand.addAttribute("deps", depsList, buildRule.label()));
//     }
//   }
//   return commands.build();
// }
// 
// Path: src/main/java/com/google/devtools/build/bfg/BuildozerCommandCreator.java
// static Iterable<Path> getBuildFilesForBuildozer(
//     Graph<BuildRule> buildRuleGraph, Path workspacePath) {
//   Function<BuildRule, Path> relativePathForRule =
//       rule -> workspacePath.resolve(rule.label().split("//")[1].split(":")[0]);
// 
//   return buildRuleGraph
//       .nodes()
//       .stream()
//       .filter(buildRule -> buildRule.shouldAddDeps())
//       .map(relativePathForRule)
//       .collect(toImmutableSet());
// }


import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.bfg.BuildozerCommandCreator.computeBuildozerCommands;
import static com.google.devtools.build.bfg.BuildozerCommandCreator.getBuildFilesForBuildozer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
        newProjectBuildRule("/workspace/java/package/", "/workspace/java/package/Example.java");
    ExternalBuildRule dstA = ExternalBuildRule.create("//java/other:Other");
    ExternalBuildRule dstB = ExternalBuildRule.create("//java/something:Something");

    buildRuleGraph.putEdge(src, dstA);
    buildRuleGraph.putEdge(dstA, dstB);

    ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
    assertThat(actual)
        .containsExactly(
            "new java_library Example|//java/package:__pkg__",
            "add srcs Example.java|//java/package:Example",
            "add deps //java/other:Other|//java/package:Example");
  }

  private MutableGraph<BuildRule> newGraph() {
    return GraphBuilder.directed().allowsSelfLoops(false).build();
  }

  /**
   * Given a DAG containing external and project rules, this test ensures Build files are only
   * listed for project rules, and ignored for external rules.
   */
  @Test
  public void getBuildFilesForBuildozer_returnsProjectRule() {
    MutableGraph<BuildRule> buildRuleGraph = newGraph();
    buildRuleGraph.putEdge(
        newProjectBuildRule("/workspace/java/package/", "Example.java"),
        ExternalBuildRule.create("//java/other:Other"));

// Path: src/main/java/com/google/devtools/build/bfg/BuildozerCommandCreator.java
// static ImmutableList<String> computeBuildozerCommands(Graph<BuildRule> buildRuleDAG) {
//   ImmutableList.Builder<String> commands = ImmutableList.builder();
//   for (BuildRule buildRule : buildRuleDAG.nodes()) {
//     List<String> initialCommands = buildRule.getCreatingBuildozerCommands();
//     commands.addAll(initialCommands);
//     List<String> depsList = getDepsForBuildRule(buildRuleDAG, buildRule);
//     if (buildRule.shouldAddDeps() && !depsList.isEmpty()) {
//       commands.add(BuildozerCommand.addAttribute("deps", depsList, buildRule.label()));
//     }
//   }
//   return commands.build();
// }
// 
// Path: src/main/java/com/google/devtools/build/bfg/BuildozerCommandCreator.java
// static Iterable<Path> getBuildFilesForBuildozer(
//     Graph<BuildRule> buildRuleGraph, Path workspacePath) {
//   Function<BuildRule, Path> relativePathForRule =
//       rule -> workspacePath.resolve(rule.label().split("//")[1].split(":")[0]);
// 
//   return buildRuleGraph
//       .nodes()
//       .stream()
//       .filter(buildRule -> buildRule.shouldAddDeps())
//       .map(relativePathForRule)
//       .collect(toImmutableSet());
// }


// Path: src/test/java/com/google/devtools/build/bfg/BuildozerCommandCreatorTest.java
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.bfg.BuildozerCommandCreator.computeBuildozerCommands;
import static com.google.devtools.build.bfg.BuildozerCommandCreator.getBuildFilesForBuildozer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

        newProjectBuildRule("/workspace/java/package/", "/workspace/java/package/Example.java");
    ExternalBuildRule dstA = ExternalBuildRule.create("//java/other:Other");
    ExternalBuildRule dstB = ExternalBuildRule.create("//java/something:Something");

    buildRuleGraph.putEdge(src, dstA);
    buildRuleGraph.putEdge(dstA, dstB);

    ImmutableList<String> actual = computeBuildozerCommands(buildRuleGraph);
    assertThat(actual)
        .containsExactly(
            "new java_library Example|//java/package:__pkg__",
            "add srcs Example.java|//java/package:Example",
            "add deps //java/other:Other|//java/package:Example");
  }

  private MutableGraph<BuildRule> newGraph() {
    return GraphBuilder.directed().allowsSelfLoops(false).build();
  }

  /**
   * Given a DAG containing external and project rules, this test ensures Build files are only
   * listed for project rules, and ignored for external rules.
   */
  @Test
  public void getBuildFilesForBuildozer_returnsProjectRule() {
    MutableGraph<BuildRule> buildRuleGraph = newGraph();
    buildRuleGraph.putEdge(
        newProjectBuildRule("/workspace/java/package/", "Example.java"),
        ExternalBuildRule.create("//java/other:Other"));

    Iterable<Path> actual = getBuildFilesForBuildozer(buildRuleGraph, DEFAULT_WORKSPACE);