use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method scan_single_file_with_dumb_file_should_fail.
@Test
public void scan_single_file_with_dumb_file_should_fail() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = "!!dummy";
thrown.expectMessage(filename);
JavaAstScanner.scanSingleFileForTests(new File(filename), new VisitorsBridge(null));
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_report_analysis_error_in_sonarLint_context_withSQ_6_0.
@Test
public void should_report_analysis_error_in_sonarLint_context_withSQ_6_0() {
JavaAstScanner scanner = defaultJavaAstScanner();
FakeAuditListener listener = spy(new FakeAuditListener());
SonarComponents sonarComponents = mock(SonarComponents.class);
when(sonarComponents.reportAnalysisError(any(RecognitionException.class), any(File.class))).thenReturn(true);
scanner.setVisitorBridge(new VisitorsBridge(Lists.newArrayList(listener), Lists.newArrayList(), sonarComponents));
scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerParseError.txt")));
verify(sonarComponents).reportAnalysisError(any(RecognitionException.class), any(File.class));
verifyZeroInteractions(listener);
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_propagate_SOError.
@Test
public void should_propagate_SOError() {
thrown.expect(StackOverflowError.class);
JavaAstScanner scanner = defaultJavaAstScanner();
scanner.setVisitorBridge(new VisitorsBridge(new CheckThrowingSOError()));
scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerNoParseError.txt")));
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class JavaAstScannerTest method should_interrupt_analysis_when_InterruptedException_is_thrown.
@Test
public void should_interrupt_analysis_when_InterruptedException_is_thrown() {
File file = new File("src/test/files/metrics/NoSonar.java");
thrown.expectMessage("Analysis cancelled");
thrown.expect(new AnalysisExceptionBaseMatcher(RecognitionException.class, "instanceof AnalysisException with RecognitionException cause"));
JavaAstScanner.scanSingleFileForTests(file, new VisitorsBridge(new CheckThrowingException(new RecognitionException(42, "interrupted", new InterruptedException()))));
}
use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.
the class DefaultJavaResourceLocatorTest method setup.
@BeforeClass
public static void setup() {
JavaClasspath javaClasspath = mock(JavaClasspath.class);
when(javaClasspath.getBinaryDirs()).thenReturn(Lists.newArrayList(new File("target/test-classes")));
when(javaClasspath.getElements()).thenReturn(Lists.newArrayList(new File("target/test-classes")));
SensorContext sensorContext = mock(SensorContext.class);
File file = new File("src/test/java/org/sonar/java/DefaultJavaResourceLocatorTest.java");
when(sensorContext.getResource(any(InputPath.class))).thenReturn(org.sonar.api.resources.File.create(file.getPath()));
DefaultFileSystem fs = new DefaultFileSystem(new File(""));
fs.add(new TestInputFileBuilder("", file.getPath()).build());
DefaultJavaResourceLocator jrl = new DefaultJavaResourceLocator(fs, javaClasspath);
jrl.setSensorContext(sensorContext);
org.sonar.java.ast.JavaAstScanner.scanSingleFileForTests(file, new VisitorsBridge(jrl));
javaResourceLocator = jrl;
}
Aggregations