@Test
  public void testJavaSurefireDontCrashAnalysis() throws Exception {

    File surefireReport = new File(baseDir, "reports/TEST-FooTest.xml");
    FileUtils.write(
        surefireReport,
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<testsuite name=\"FooTest\" time=\"0.121\" tests=\"1\" errors=\"0\" skipped=\"0\" failures=\"0\">\n"
            + "<testcase name=\"errorAnalysis\" classname=\"FooTest\" time=\"0.031\"/>\n"
            + "</testsuite>");

    ClientInputFile inputFile =
        prepareInputFile(
            "Foo.java",
            "public class Foo {\n"
                + "  public void foo() {\n"
                + "    int x;\n"
                + "    System.out.println(\"Foo\");\n"
                + "    System.out.println(\"Foo\"); //NOSONAR\n"
                + "  }\n"
                + "}",
            false);

    ClientInputFile inputFileTest =
        prepareInputFile(
            "FooTest.java",
            "public class FooTest {\n" + "  public void testFoo() {\n" + "  }\n" + "}",
            true);

    final List<Issue> issues = new ArrayList<>();
    AnalysisResults results =
        sonarlint.analyze(
            new StandaloneAnalysisConfiguration(
                baseDir.toPath(),
                temp.newFolder().toPath(),
                Arrays.asList(inputFile, inputFileTest),
                ImmutableMap.of("sonar.junit.reportsPath", "reports/")),
            issue -> issues.add(issue));

    assertThat(results.fileCount()).isEqualTo(2);

    assertThat(issues)
        .extracting("ruleKey", "startLine", "inputFile.path")
        .containsOnly(
            tuple("squid:S106", 4, inputFile.getPath()),
            tuple("squid:S1220", null, inputFile.getPath()),
            tuple("squid:UndocumentedApi", 1, inputFile.getPath()),
            tuple("squid:UndocumentedApi", 2, inputFile.getPath()),
            tuple("squid:S1481", 3, inputFile.getPath()),
            tuple("squid:S2187", 1, inputFileTest.getPath()));
  }
  @Test
  public void analysisErrors() throws Exception {
    ClientInputFile inputFile =
        prepareInputFile(
            "foo.xoo", "function foo() {\n" + "  var xoo;\n" + "  var y; //NOSONAR\n" + "}", false);
    prepareInputFile("foo.xoo.error", "1,2,error analysing\n2,3,error analysing", false);

    final List<Issue> issues = new ArrayList<>();
    AnalysisResults results =
        sonarlint.analyze(
            new StandaloneAnalysisConfiguration(
                baseDir.toPath(),
                temp.newFolder().toPath(),
                Arrays.asList(inputFile),
                ImmutableMap.of()),
            issue -> issues.add(issue));
    assertThat(results.failedAnalysisFiles()).containsExactly(inputFile);
    assertThat(issues)
        .extracting("ruleKey", "startLine", "startLineOffset", "inputFile.path")
        .containsOnly(tuple("xoo:HasTag", 2, 6, inputFile.getPath()));
  }