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);
}
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);
}
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");
}
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);
}
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());
}
Aggregations