Search in sources :

Example 6 with JavaVersionImpl

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");
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) Test(org.junit.Test)

Example 7 with JavaVersionImpl

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");
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) Test(org.junit.Test)

Example 8 with JavaVersionImpl

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");
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) Test(org.junit.Test)

Example 9 with JavaVersionImpl

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");
}
Also used : JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) Test(org.junit.Test)

Example 10 with JavaVersionImpl

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;
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) Server(org.sonar.api.platform.Server) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) JavaResourceLocator(org.sonar.plugins.java.api.JavaResourceLocator) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) FileSystem(org.sonar.api.batch.fs.FileSystem) CheckFactory(org.sonar.api.batch.rule.CheckFactory) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) FileLinesContext(org.sonar.api.measures.FileLinesContext)

Aggregations

JavaVersionImpl (org.sonar.java.model.JavaVersionImpl)16 File (java.io.File)8 Test (org.junit.Test)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 InputFile (org.sonar.api.batch.fs.InputFile)4 JavaResourceLocator (org.sonar.plugins.java.api.JavaResourceLocator)4 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)3 JavaSquid (org.sonar.java.JavaSquid)3 FileSystem (org.sonar.api.batch.fs.FileSystem)2 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 CheckFactory (org.sonar.api.batch.rule.CheckFactory)2 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Server (org.sonar.api.platform.Server)1 SonarComponents (org.sonar.java.SonarComponents)1