JavaSquidSensor implements Sensor { @Override public void execute(SensorContext context) { sonarComponents.setSensorContext(context); List<Class<? extends JavaCheck>> checks = ImmutableList.<Class<? extends JavaCheck>>builder() .addAll(CheckList.getJavaChecks()) .addAll(CheckList.getDebugChecks()) .build(); sonarComponents.registerCheckClasses(CheckList.REPOSITORY_KEY, checks); sonarComponents.registerTestCheckClasses(CheckList.REPOSITORY_KEY, CheckList.getJavaTestChecks()); Measurer measurer = new Measurer(context, noSonarFilter); JavaSquid squid = new JavaSquid(getJavaVersion(), sonarComponents, measurer, javaResourceLocator, postAnalysisIssueFilter, sonarComponents.checkClasses()); squid.scan(getSourceFiles(), getTestFiles(), runJasper(context)); } JavaSquidSensor(SonarComponents sonarComponents, FileSystem fs, JavaResourceLocator javaResourceLocator,
                         Configuration settings, NoSonarFilter noSonarFilter, PostAnalysisIssueFilter postAnalysisIssueFilter);  JavaSquidSensor(SonarComponents sonarComponents, FileSystem fs, JavaResourceLocator javaResourceLocator,
                         Configuration settings, NoSonarFilter noSonarFilter,
                         PostAnalysisIssueFilter postAnalysisIssueFilter, @Nullable Jasper jasper); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); @Override String toString();  }
@Test void should_invoke_visitors_on_generated_code() throws Exception { Path base = tmp.newFolder().toPath(); Path generatedFilePath = tmp.newFile("Generated.java").toPath(); Files.write(generatedFilePath, "class Generated {}".getBytes()); GeneratedFile generatedFile = new GeneratedFile(generatedFilePath); SensorContextTester context = SensorContextTester.create(base); SonarComponents sonarComponents = createSonarComponentsMock(context); JavaFileScanner javaFileScanner = mock(JavaFileScanner.class); JspCodeScanner testCodeVisitor = mock(JspCodeScanner.class); when(sonarComponents.jspCodeVisitors()).thenReturn(asList(testCodeVisitor)); when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[]{javaFileScanner}); Jasper jasper = mock(Jasper.class); when(jasper.generateFiles(any(), any())).thenReturn(asList(generatedFile)); JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, context.fileSystem(), mock(JavaResourceLocator.class), new MapSettings().asConfig(), mock(NoSonarFilter.class), null, jasper); jss.execute(context); ArgumentCaptor<JavaFileScannerContext> scannerContext = ArgumentCaptor.forClass(JavaFileScannerContext.class); verify(testCodeVisitor, times(1)).scanFile(scannerContext.capture()); assertThat(scannerContext.getValue().getInputFile()).isSameAs(generatedFile); verify(javaFileScanner, never()).scanFile(any()); }