ApexSquidSensor implements Sensor { @Override public void analyse(Project project, SensorContext context) { this.context = context; List<SquidAstVisitor<Grammar>> visitors = Lists.newArrayList(checks.all()); scanner = ApexAstScanner.create(createConfiguration(), visitors.toArray(new SquidAstVisitor[visitors.size()])); scanner.scanFiles(Lists.newArrayList(fileSystem.files(filePredicate))); Collection<SourceCode> squidSourceFiles = scanner.getIndex() .search(new QueryByType(SourceFile.class)); save(squidSourceFiles); } ApexSquidSensor(FileSystem fileSystem, ResourcePerspectives perspectives, CheckFactory checkFactory); @Override boolean shouldExecuteOnProject(Project project); @Override void analyse(Project project, SensorContext context); @Override String toString();  }
@Test public void testAnalyse() { String relativePath = "src/test/resources/sensor/Book.cls"; DefaultInputFile inputFile = new DefaultInputFile(relativePath).setLanguage(Apex.KEY); inputFile.setAbsolutePath((new File(relativePath)).getAbsolutePath()); fileSystem.add(inputFile); Issuable issuable = mock(Issuable.class); Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class); when(perspectives.as(Mockito.eq(Issuable.class), Mockito.any(InputFile.class))).thenReturn(issuable); when(issuable.newIssueBuilder()).thenReturn(issueBuilder); when(issueBuilder.ruleKey(Mockito.any(RuleKey.class))).thenReturn(issueBuilder); when(issueBuilder.line(Mockito.any(Integer.class))).thenReturn(issueBuilder); when(issueBuilder.message(Mockito.any(String.class))).thenReturn(issueBuilder); Project project = new Project("cls"); SensorContext context = mock(SensorContext.class); squidSensor.analyse(project, context); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FILES), eq(1.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.LINES), eq(7.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.NCLOC), eq(6.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.STATEMENTS), eq(2.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.FUNCTIONS), eq(1.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.CLASSES), eq(1.0)); verify(context).saveMeasure(any(InputFile.class), eq(CoreMetrics.COMPLEXITY), eq(1.0)); }