Search in sources :

Example 1 with VisitorsBridgeForTests

use of org.sonar.java.model.VisitorsBridgeForTests in project sonar-java by SonarSource.

the class AnyRuleIssueFilterTest method scanFile.

private static void scanFile(JavaIssueFilter filter) {
    VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(Collections.singletonList(filter), Collections.emptyList(), null);
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/filters/AnyRuleIssueFilter.java"), visitorsBridge);
}
Also used : File(java.io.File) VisitorsBridgeForTests(org.sonar.java.model.VisitorsBridgeForTests)

Example 2 with VisitorsBridgeForTests

use of org.sonar.java.model.VisitorsBridgeForTests in project sonar-java by SonarSource.

the class BaseTreeVisitorIssueFilterTest method scanFile.

private static void scanFile(JavaIssueFilter filter) {
    VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(Collections.singletonList(filter), Collections.emptyList(), null);
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/filters/BaseTreeVisitorIssueFilter.java"), visitorsBridge);
}
Also used : File(java.io.File) VisitorsBridgeForTests(org.sonar.java.model.VisitorsBridgeForTests)

Example 3 with VisitorsBridgeForTests

use of org.sonar.java.model.VisitorsBridgeForTests in project sonar-java by SonarSource.

the class ParsingErrorCheckTest method test.

@Test
public void test() {
    SonarComponents sonarComponents = mock(SonarComponents.class);
    when(sonarComponents.fileContent(any())).thenCallRealMethod();
    when(sonarComponents.fileLength(any())).thenCallRealMethod();
    VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(new ParsingErrorCheck(), sonarComponents);
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/ParsingError.java"), visitorsBridge);
    Set<AnalyzerMessage> issues = visitorsBridge.lastCreatedTestContext().getIssues();
    assertThat(issues).hasSize(1);
    AnalyzerMessage issue = issues.iterator().next();
    assertThat(issue.getLine()).isEqualTo(1);
    assertThat(issue.getMessage()).isEqualTo("Parse error");
}
Also used : SonarComponents(org.sonar.java.SonarComponents) AnalyzerMessage(org.sonar.java.AnalyzerMessage) File(java.io.File) VisitorsBridgeForTests(org.sonar.java.model.VisitorsBridgeForTests) Test(org.junit.Test)

Example 4 with VisitorsBridgeForTests

use of org.sonar.java.model.VisitorsBridgeForTests in project sonar-java by SonarSource.

the class JavaCheckVerifier method scanFile.

private static void scanFile(String filename, JavaFileScanner check, JavaCheckVerifier javaCheckVerifier, Collection<File> classpath, boolean withSemantic) {
    JavaFileScanner expectedIssueCollector = new ExpectedIssueCollector(javaCheckVerifier);
    VisitorsBridgeForTests visitorsBridge;
    File file = new File(filename);
    SonarComponents sonarComponents = CheckVerifier.sonarComponents(file);
    if (withSemantic) {
        visitorsBridge = new VisitorsBridgeForTests(Lists.newArrayList(check, expectedIssueCollector), Lists.newArrayList(classpath), sonarComponents);
    } else {
        visitorsBridge = new VisitorsBridgeForTests(Lists.newArrayList(check, expectedIssueCollector), sonarComponents);
    }
    JavaAstScanner.scanSingleFileForTests(file, visitorsBridge, javaCheckVerifier.javaVersion);
    VisitorsBridgeForTests.TestJavaFileScannerContext testJavaFileScannerContext = visitorsBridge.lastCreatedTestContext();
    if (testJavaFileScannerContext == null) {
        Fail.fail("Semantic was required but it was not possible to create it. Please checks the logs to find out the reason.");
    }
    javaCheckVerifier.checkIssues(testJavaFileScannerContext.getIssues(), javaCheckVerifier.providedJavaVersion);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaFileScanner(org.sonar.plugins.java.api.JavaFileScanner) File(java.io.File) VisitorsBridgeForTests(org.sonar.java.model.VisitorsBridgeForTests)

Example 5 with VisitorsBridgeForTests

use of org.sonar.java.model.VisitorsBridgeForTests in project sonar-java by SonarSource.

the class JavaCheckVerifier method scanFile.

private void scanFile(String filename, JavaFileScanner[] checks, Collection<File> classpath) {
    List<JavaFileScanner> visitors = new ArrayList<>(Arrays.asList(checks));
    visitors.add(expectations.parser());
    VisitorsBridgeForTests visitorsBridge = new VisitorsBridgeForTests(visitors, Lists.newArrayList(classpath), null);
    JavaAstScanner.scanSingleFileForTests(new File(filename), visitorsBridge);
    VisitorsBridgeForTests.TestJavaFileScannerContext testJavaFileScannerContext = visitorsBridge.lastCreatedTestContext();
    checkIssues(testJavaFileScannerContext.getIssues());
}
Also used : JavaFileScanner(org.sonar.plugins.java.api.JavaFileScanner) ArrayList(java.util.ArrayList) File(java.io.File) VisitorsBridgeForTests(org.sonar.java.model.VisitorsBridgeForTests)

Aggregations

File (java.io.File)7 VisitorsBridgeForTests (org.sonar.java.model.VisitorsBridgeForTests)7 AnalyzerMessage (org.sonar.java.AnalyzerMessage)3 Test (org.junit.Test)2 SonarComponents (org.sonar.java.SonarComponents)2 JavaFileScanner (org.sonar.plugins.java.api.JavaFileScanner)2 ArrayList (java.util.ArrayList)1 FilterableIssue (org.sonar.api.scan.issue.filter.FilterableIssue)1 Rule (org.sonar.check.Rule)1 JavaCheck (org.sonar.plugins.java.api.JavaCheck)1