use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_handle_analysis_cancellation.
@Test
public void should_handle_analysis_cancellation() throws Exception {
JavaFileScanner visitor = spy(new JavaFileScanner() {
@Override
public void scanFile(JavaFileScannerContext context) {
// do nothing
}
});
SonarComponents sonarComponents = mock(SonarComponents.class);
when(sonarComponents.analysisCancelled()).thenReturn(true);
JavaAstScanner scanner = new JavaAstScanner(JavaParser.createParser(), sonarComponents);
scanner.setVisitorBridge(new VisitorsBridge(Lists.newArrayList(visitor), Lists.newArrayList(), sonarComponents));
scanner.scan(ImmutableList.of(new File("src/test/files/metrics/NoSonar.java")));
verifyZeroInteractions(visitor);
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_swallow_log_and_report_checks_exceptions_for_symbolic_execution.
@Test
public void should_swallow_log_and_report_checks_exceptions_for_symbolic_execution() {
JavaAstScanner scanner = new JavaAstScanner(JavaParser.createParser(), null);
logTester.clear();
SonarComponents sonarComponent = new SonarComponents(null, context.fileSystem(), null, null, null, null);
context.setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
sonarComponent.setSensorContext(context);
scanner.setVisitorBridge(new VisitorsBridge(Collections.singletonList(new SECheck() {
@Override
public void init(MethodTree methodTree, CFG cfg) {
throw new NullPointerException("nobody expect the spanish inquisition !");
}
}), new ArrayList<>(), sonarComponent, SymbolicExecutionMode.ENABLED_WITHOUT_X_FILE));
scanner.scan(ImmutableList.of(new File("src/test/resources/se/MethodBehavior.java")));
assertThat(logTester.logs(LoggerLevel.ERROR)).hasSize(1);
assertThat(logTester.logs(LoggerLevel.ERROR).get(0)).startsWith("Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor");
assertThat(sonarComponent.analysisErrors).hasSize(1);
assertThat(sonarComponent.analysisErrors.get(0).getKind()).isSameAs(AnalysisError.Kind.SE_ERROR);
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method noSonarLines.
@Test
public void noSonarLines() throws Exception {
File file = new File("src/test/files/metrics/NoSonar.java");
DefaultInputFile resource = new TestInputFileBuilder("", "src/test/files/metrics/NoSonar.java").build();
fs.add(resource);
NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
JavaAstScanner.scanSingleFileForTests(file, new VisitorsBridge(new Measurer(fs, context, noSonarFilter)));
verify(noSonarFilter).noSonarInFile(resource, ImmutableSet.of(8));
// No Sonar on tests files
NoSonarFilter noSonarFilterForTest = mock(NoSonarFilter.class);
JavaAstScanner.scanSingleFileForTests(file, new VisitorsBridge(new Measurer(fs, context, noSonarFilterForTest).new TestFileMeasurer()));
verify(noSonarFilterForTest).noSonarInFile(resource, ImmutableSet.of(8));
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_not_fail_whole_analysis_upon_parse_error_and_notify_audit_listeners.
@Test
public void should_not_fail_whole_analysis_upon_parse_error_and_notify_audit_listeners() {
FakeAuditListener listener = spy(new FakeAuditListener());
JavaAstScanner scanner = defaultJavaAstScanner();
scanner.setVisitorBridge(new VisitorsBridge(listener));
scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerParseError.txt")));
verify(listener).processRecognitionException(any(RecognitionException.class));
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class SemanticOrderResolution method verify_generic_substitution.
@Test
public void verify_generic_substitution() {
MyVisitor myVisitor = new MyVisitor();
JavaAstScanner.scanSingleFileForTests(new File("src/test/java/org/sonar/java/resolve/targets/bytecodeGenerics/Main.java"), new VisitorsBridge(Lists.newArrayList(myVisitor), Lists.newArrayList(new File("target/test-classes")), null));
assertThat(myVisitor.classes).isEqualTo(2);
}
Aggregations