bael-4909: add unit test

This commit is contained in:
sharifi 2021-05-05 09:50:45 +04:30
parent f77b9bee84
commit cb17634fd6
2 changed files with 56 additions and 0 deletions

View File

@ -51,6 +51,11 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
<build>
@ -74,6 +79,7 @@
<junit.jupiter.version>5.7.0</junit.jupiter.version>
<assertj.version>3.17.2</assertj.version>
<mockserver.version>5.11.1</mockserver.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
</properties>
</project>

View File

@ -0,0 +1,50 @@
package com.baeldung.version;
import org.apache.commons.lang3.SystemUtils;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class VersionUnitTest {
@Test
public void givenJava_whenUsingRuntime_thenGetVersion() {
String expectedVersion = "11";
Runtime.Version runtimeVersion = Runtime.version();
String version = String.valueOf(runtimeVersion.version().get(0));
Assertions.assertThat(version).isEqualTo(expectedVersion);
}
@Test
@Disabled("Disabled until Java version is 11")
public void givenJava_whenUsingCommonsLang_thenGetVersion() {
String expectedVersion = "8";
String version = SystemUtils.JAVA_SPECIFICATION_VERSION;
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int separator = version.indexOf(".");
if (separator != -1) {
version = version.substring(0, separator);
}
}
Assertions.assertThat(version).isEqualTo(expectedVersion);
}
@Test
@Disabled("Disabled until Java version is 11")
public void givenJava_whenUsingSystemProp_thenGetVersion() {
String expectedVersion = "8";
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int separator = version.indexOf(".");
if (separator != -1) {
version = version.substring(0, separator);
}
}
Assertions.assertThat(version).isEqualTo(expectedVersion);
}
}