@VisibleForTesting
 protected void analyseFiles(
     SensorContext context,
     List<TreeVisitor> treeVisitors,
     Iterable<InputFile> inputFiles,
     ProgressReport progressReport) {
   boolean success = false;
   try {
     for (InputFile inputFile : inputFiles) {
       // check for cancellation of the analysis (by SonarQube or SonarLint). See SONARJS-761.
       if (context.getSonarQubeVersion().isGreaterThanOrEqual(V6_0) && context.isCancelled()) {
         throw new CancellationException(
             "Analysis interrupted because the SensorContext is in cancelled state");
       }
       if (!isExcluded(inputFile.file())) {
         analyse(context, inputFile, treeVisitors);
       }
       progressReport.nextFile();
     }
     success = true;
   } catch (CancellationException e) {
     // do not propagate the exception
     LOG.debug(e.toString());
   } finally {
     stopProgressReport(progressReport, success);
   }
 }
  @Test
  public void should_analyse() {
    ProjectFileSystem fs = mock(ProjectFileSystem.class);
    when(fs.getSourceCharset()).thenReturn(Charset.forName("UTF-8"));
    InputFile inputFile =
        InputFileUtils.create(
            new File("src/test/resources/cpd"), new File("src/test/resources/cpd/Person.js"));
    when(fs.mainFiles(JavaScript.KEY)).thenReturn(ImmutableList.of(inputFile));
    Project project = new Project("key");
    project.setFileSystem(fs);
    SensorContext context = mock(SensorContext.class);

    sensor.analyse(project, context);

    verify(context)
        .saveMeasure(Mockito.any(Resource.class), Mockito.eq(CoreMetrics.FILES), Mockito.eq(1.0));
    verify(context)
        .saveMeasure(Mockito.any(Resource.class), Mockito.eq(CoreMetrics.LINES), Mockito.eq(22.0));
    verify(context)
        .saveMeasure(Mockito.any(Resource.class), Mockito.eq(CoreMetrics.NCLOC), Mockito.eq(10.0));
    verify(context)
        .saveMeasure(
            Mockito.any(Resource.class), Mockito.eq(CoreMetrics.FUNCTIONS), Mockito.eq(2.0));
    verify(context)
        .saveMeasure(
            Mockito.any(Resource.class), Mockito.eq(CoreMetrics.STATEMENTS), Mockito.eq(6.0));
    verify(context)
        .saveMeasure(
            Mockito.any(Resource.class), Mockito.eq(CoreMetrics.COMPLEXITY), Mockito.eq(3.0));
    verify(context)
        .saveMeasure(
            Mockito.any(Resource.class), Mockito.eq(CoreMetrics.COMMENT_LINES), Mockito.eq(2.0));
  }