use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaVersionAwareVisitorTest method no_java_version_matching.
@Test
public void no_java_version_matching() {
checkIssues(new JavaVersionImpl(6));
assertThat(messages).containsExactly("SimpleCheck", "ContextualCheck_6");
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaVersionAwareVisitorTest method only_checks_with_adequate_java_version_higher_than_configuration_version_are_executed.
@Test
public void only_checks_with_adequate_java_version_higher_than_configuration_version_are_executed() {
checkIssues(new JavaVersionImpl(7));
assertThat(messages).containsExactly("JavaVersionCheck_7", "SimpleCheck", "ContextualCheck_7");
checkIssues(new JavaVersionImpl(8));
assertThat(messages).containsExactly("JavaVersionCheck_7", "JavaVersionCheck_8", "SimpleCheck", "ContextualCheck_8");
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaVersionAwareVisitorTest method all_check_executed_when_no_java_version.
@Test
public void all_check_executed_when_no_java_version() {
checkIssues(new JavaVersionImpl());
assertThat(messages).containsExactly("JavaVersionCheck_7", "JavaVersionCheck_8", "SimpleCheck", "ContextualCheck");
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaVersionAwareVisitorTest method all_check_executed_when_invalid_java_version.
@Test
public void all_check_executed_when_invalid_java_version() {
checkIssues(new JavaVersionImpl());
assertThat(messages).containsExactly("JavaVersionCheck_7", "JavaVersionCheck_8", "SimpleCheck", "ContextualCheck");
}
use of org.sonar.java.model.JavaVersionImpl in project sonar-java by SonarSource.
the class JavaSquidTest method collectAnalysisErrors.
private SonarComponents collectAnalysisErrors(String code) throws IOException {
SensorContextTester context = SensorContextTester.create(temp.getRoot().getAbsoluteFile());
File file = temp.newFile().getAbsoluteFile();
Files.write(code, file, StandardCharsets.UTF_8);
DefaultInputFile defaultFile = new TestInputFileBuilder(temp.getRoot().getAbsolutePath(), file.getName()).setLanguage("java").initMetadata(new String(java.nio.file.Files.readAllBytes(file.getAbsoluteFile().toPath()), StandardCharsets.UTF_8)).setCharset(StandardCharsets.UTF_8).build();
context.fileSystem().add(defaultFile);
context.setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
// Mock visitor for metrics.
FileLinesContext fileLinesContext = mock(FileLinesContext.class);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
Server server = mock(Server.class);
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
FileSystem fs = context.fileSystem();
JavaClasspath javaClasspath = mock(JavaClasspath.class);
JavaTestClasspath javaTestClasspath = mock(JavaTestClasspath.class);
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, mock(CheckFactory.class));
sonarComponents.setSensorContext(context);
JavaSquid javaSquid = new JavaSquid(new JavaVersionImpl(), sonarComponents, new Measurer(fs, context, mock(NoSonarFilter.class)), mock(JavaResourceLocator.class), null);
javaSquid.scan(Collections.singletonList(file), Collections.emptyList());
return sonarComponents;
}
Aggregations