Search in sources :

Example 16 with VisitorsBridge

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));
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 17 with VisitorsBridge

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);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) VisitorsBridge(org.sonar.java.model.VisitorsBridge) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) RecognitionException(com.sonar.sslr.api.RecognitionException) Test(org.junit.Test)

Example 18 with VisitorsBridge

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")));
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 19 with VisitorsBridge

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()))));
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) RecognitionException(com.sonar.sslr.api.RecognitionException) Test(org.junit.Test)

Example 20 with VisitorsBridge

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;
}
Also used : SensorContext(org.sonar.api.batch.SensorContext) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) InputPath(org.sonar.api.batch.fs.InputPath) VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) BeforeClass(org.junit.BeforeClass)

Aggregations

VisitorsBridge (org.sonar.java.model.VisitorsBridge)26 File (java.io.File)25 Test (org.junit.Test)24 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)11 RecognitionException (com.sonar.sslr.api.RecognitionException)4 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 SonarComponents (org.sonar.java.SonarComponents)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 Measurer (org.sonar.java.Measurer)2 SubscriptionVisitor (org.sonar.java.ast.visitors.SubscriptionVisitor)2 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)2 InterruptedIOException (java.io.InterruptedIOException)1 HashMap (java.util.HashMap)1 BeforeClass (org.junit.BeforeClass)1 SensorContext (org.sonar.api.batch.SensorContext)1 InputPath (org.sonar.api.batch.fs.InputPath)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1