/** Verify that owners are correctly detected: - one owner, multiple inputs */
  @Test
  public void verifyInputsWithOneOwnerAreCorrectlyReported()
      throws CmdLineException, IOException, InterruptedException {
    FakeProjectFilesystem filesystem =
        new FakeProjectFilesystem() {
          @Override
          public File getFileForRelativePath(String pathRelativeToProjectRoot) {
            return new ExistingFile(getRootPath(), pathRelativeToProjectRoot);
          }
        };

    ImmutableSet<String> inputs =
        ImmutableSet.of(
            "java/somefolder/badfolder/somefile.java",
            "java/somefolder/perfect.java",
            "com/test/subtest/random.java");
    ImmutableSet<Path> inputPaths = MorePaths.asPaths(inputs);

    BuildTarget target = BuildTargetFactory.newInstance("//base:name");
    TargetNode<?> targetNode = createTargetNode(target, inputPaths);

    CommandRunnerParams params = createAuditOwnerCommandRunnerParams(filesystem);
    AuditOwnerCommand.OwnersReport report =
        AuditOwnerCommand.generateOwnersReport(params, targetNode, inputs, false);
    assertTrue(report.nonFileInputs.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertTrue(report.inputsWithNoOwners.isEmpty());

    assertEquals(inputs.size(), report.owners.size());
    assertTrue(report.owners.containsKey(targetNode));
    assertEquals(targetNode.getInputs(), report.owners.get(targetNode));
  }
  /** Verify that owners are correctly detected: - one owner, multiple inputs, json output */
  @Test
  public void verifyInputsWithOneOwnerAreCorrectlyReportedInJson()
      throws CmdLineException, IOException, InterruptedException {
    FakeProjectFilesystem filesystem =
        new FakeProjectFilesystem() {
          @Override
          public File getFileForRelativePath(String pathRelativeToProjectRoot) {
            return new ExistingFile(getRootPath(), pathRelativeToProjectRoot);
          }
        };

    ImmutableSet<String> inputs =
        ImmutableSet.of(
            "java/somefolder/badfolder/somefile.java",
            "java/somefolder/perfect.java",
            "com/test/subtest/random.java");
    ImmutableSortedSet<Path> inputPaths = MorePaths.asPaths(inputs);

    BuildTarget target = BuildTargetFactory.newInstance("//base/name:name");
    TargetNode<?> targetNode = createTargetNode(target, inputPaths);

    AuditOwnerCommand command = new AuditOwnerCommand();
    CommandRunnerParams params = createAuditOwnerCommandRunnerParams(filesystem);
    AuditOwnerCommand.OwnersReport report =
        AuditOwnerCommand.generateOwnersReport(params, targetNode, inputs, false);
    command.printOwnersOnlyJsonReport(params, report);

    String expectedJson =
        Joiner.on("")
            .join(
                "{",
                "\"com/test/subtest/random.java\":[\"//base/name:name\"],",
                "\"java/somefolder/badfolder/somefile.java\":[\"//base/name:name\"],",
                "\"java/somefolder/perfect.java\":[\"//base/name:name\"]",
                "}");

    assertEquals(expectedJson, console.getTextWrittenToStdOut());
    assertEquals("", console.getTextWrittenToStdErr());
  }