@Test
  public void testShouldAnalyseReusedReports() throws Exception {
    conf.addProperty(GendarmeConstants.MODE, GendarmeSensor.MODE_REUSE_REPORT);
    conf.addProperty(GendarmeConstants.REPORTS_PATH_KEY, "**/*.xml");
    initializeSensor();
    GendarmeRunner runner = mock(GendarmeRunner.class);
    GendarmeCommandBuilder builder = GendarmeCommandBuilder.createBuilder(null, vsProject);
    builder.setExecutable(new File("FxCopCmd.exe"));
    when(runner.createCommandBuilder(eq(solution), any(VisualStudioProject.class)))
        .thenReturn(builder);

    PowerMockito.mockStatic(GendarmeRunner.class);
    when(GendarmeRunner.create(anyString(), anyString())).thenReturn(runner);

    File fakeReport = TestUtils.getResource("/Sensor/FakeGendarmeConfigFile.xml");
    PowerMockito.mockStatic(FileFinder.class);
    when(FileFinder.findFiles(solution, vsProject, "**/*.xml"))
        .thenReturn(Lists.newArrayList(fakeReport, fakeReport));

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project #1");

    SensorContext context = mock(SensorContext.class);

    sensor.analyse(project, context);

    verify(resultParser, times(2)).parse(any(File.class));
  }
  /** {@inheritDoc} */
  public void analyse(Project project, SensorContext context) {
    if (rulesProfile.getActiveRulesByRepository(FxCopConstants.REPOSITORY_KEY).isEmpty()) {
      LOG.warn(
          "/!\\ SKIP FxCop analysis: no rule defined for FxCop in the \"{}\" profil.",
          rulesProfile.getName());
      return;
    }

    fxCopResultParser.setEncoding(fileSystem.getSourceCharset());

    final File reportFile;
    File projectDir = project.getFileSystem().getBasedir();
    String reportDefaultPath =
        getMicrosoftWindowsEnvironment().getWorkingDirectory()
            + "/"
            + FxCopConstants.FXCOP_REPORT_XML;
    if (MODE_REUSE_REPORT.equalsIgnoreCase(executionMode)) {
      String reportPath =
          configuration.getString(FxCopConstants.REPORTS_PATH_KEY, reportDefaultPath);
      reportFile = FileFinder.browse(projectDir, reportPath);
      LOG.info("Reusing FxCop report: " + reportFile);
    } else {
      // prepare config file for FxCop
      File fxCopConfigFile = generateConfigurationFile();
      // and run FxCop
      try {
        FxCopRunner runner =
            FxCopRunner.create(
                configuration.getString(
                    FxCopConstants.INSTALL_DIR_KEY, FxCopConstants.INSTALL_DIR_DEFVALUE));
        launchFxCop(project, runner, fxCopConfigFile);
      } catch (FxCopException e) {
        throw new SonarException("FxCop execution failed.", e);
      }
      reportFile = new File(projectDir, reportDefaultPath);
    }

    // and analyze results
    analyseResults(reportFile);
  }