Search in sources :

Example 1 with JavaVersion

use of org.sonar.plugins.java.api.JavaVersion in project sonar-java by SonarSource.

the class JavaVersionImplTest method test_fromString.

@Test
public void test_fromString() throws Exception {
    JavaVersion version;
    version = JavaVersionImpl.fromString(null);
    assertThat(version.isNotSet()).isTrue();
    assertThat(version.asInt()).isEqualTo(-1);
    version = JavaVersionImpl.fromString("jdk1.6");
    assertThat(version.isNotSet()).isTrue();
    assertThat(version.asInt()).isEqualTo(-1);
    version = JavaVersionImpl.fromString("1.6");
    assertThat(version.isNotSet()).isFalse();
    assertThat(version.asInt()).isEqualTo(6);
    version = JavaVersionImpl.fromString("7");
    assertThat(version.isNotSet()).isFalse();
    assertThat(version.asInt()).isEqualTo(7);
}
Also used : JavaVersion(org.sonar.plugins.java.api.JavaVersion) Test(org.junit.Test)

Example 2 with JavaVersion

use of org.sonar.plugins.java.api.JavaVersion in project sonar-java by SonarSource.

the class JavaVersionImplTest method compatibilityMesssages.

@Test
public void compatibilityMesssages() throws Exception {
    JavaVersion version;
    version = new JavaVersionImpl();
    assertThat(version.java7CompatibilityMessage()).isEqualTo(" (sonar.java.source not set. Assuming 7 or greater.)");
    assertThat(version.java8CompatibilityMessage()).isEqualTo(" (sonar.java.source not set. Assuming 8 or greater.)");
    version = new JavaVersionImpl(6);
    assertThat(version.java7CompatibilityMessage()).isEmpty();
    assertThat(version.java8CompatibilityMessage()).isEmpty();
}
Also used : JavaVersion(org.sonar.plugins.java.api.JavaVersion) Test(org.junit.Test)

Example 3 with JavaVersion

use of org.sonar.plugins.java.api.JavaVersion in project sonar-java by SonarSource.

the class JavaSquidSensor method getJavaVersion.

private JavaVersion getJavaVersion() {
    JavaVersion javaVersion = JavaVersionImpl.fromString(settings.get(Java.SOURCE_VERSION).orElse(null));
    LOG.info("Configured Java source version (" + Java.SOURCE_VERSION + "): " + javaVersion);
    return javaVersion;
}
Also used : JavaVersion(org.sonar.plugins.java.api.JavaVersion)

Example 4 with JavaVersion

use of org.sonar.plugins.java.api.JavaVersion in project sonar-java by SonarSource.

the class JavaVersionImplTest method test_toString.

@Test
public void test_toString() throws Exception {
    JavaVersion version;
    version = new JavaVersionImpl();
    assertThat(version.toString()).isEqualTo("none");
    version = new JavaVersionImpl(7);
    assertThat(version.toString()).isEqualTo("7");
}
Also used : JavaVersion(org.sonar.plugins.java.api.JavaVersion) Test(org.junit.Test)

Example 5 with JavaVersion

use of org.sonar.plugins.java.api.JavaVersion in project sonar-java by SonarSource.

the class JavaVersionImplTest method no_version_set.

@Test
public void no_version_set() throws Exception {
    JavaVersion version = new JavaVersionImpl();
    assertThat(version.isJava7Compatible()).isTrue();
    assertThat(version.isJava8Compatible()).isTrue();
    assertThat(version.asInt()).isEqualTo(-1);
}
Also used : JavaVersion(org.sonar.plugins.java.api.JavaVersion) Test(org.junit.Test)

Aggregations

JavaVersion (org.sonar.plugins.java.api.JavaVersion)8 Test (org.junit.Test)7