From 40a17f0f63fb0fed6549dc920922fa4b1c825f58 Mon Sep 17 00:00:00 2001 From: sergio41 Date: Fri, 6 Mar 2020 18:05:48 +0100 Subject: [PATCH] BAEL-3765: Code Upload (#8804) --- .../com/baeldung/version/VersionObtainer.java | 20 +++++++++++++ .../version/VersionObtainerUnitTest.java | 30 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 spring-5/src/main/java/com/baeldung/version/VersionObtainer.java create mode 100644 spring-5/src/test/java/com/baeldung/version/VersionObtainerUnitTest.java diff --git a/spring-5/src/main/java/com/baeldung/version/VersionObtainer.java b/spring-5/src/main/java/com/baeldung/version/VersionObtainer.java new file mode 100644 index 0000000000..392cc44a72 --- /dev/null +++ b/spring-5/src/main/java/com/baeldung/version/VersionObtainer.java @@ -0,0 +1,20 @@ +package com.baeldung.version; + +import org.springframework.boot.system.JavaVersion; +import org.springframework.boot.system.SystemProperties; +import org.springframework.core.SpringVersion; + +public class VersionObtainer { + + public String getSpringVersion() { + return SpringVersion.getVersion(); + } + + public String getJavaVersion() { + return JavaVersion.getJavaVersion().toString(); + } + + public String getJdkVersion() { + return SystemProperties.get("java.version"); + } +} diff --git a/spring-5/src/test/java/com/baeldung/version/VersionObtainerUnitTest.java b/spring-5/src/test/java/com/baeldung/version/VersionObtainerUnitTest.java new file mode 100644 index 0000000000..6d77cd1403 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/version/VersionObtainerUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.version; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = VersionObtainer.class) +public class VersionObtainerUnitTest { + + public VersionObtainer version = new VersionObtainer(); + + @Test + public void testGetSpringVersion() { + String res = version.getSpringVersion(); + assertThat(res).isNotEmpty(); + } + + @Test + public void testGetJdkVersion() { + String res = version.getJdkVersion(); + assertThat(res).isNotEmpty(); + } + + @Test + public void testGetJavaVersion() { + String res = version.getJavaVersion(); + assertThat(res).isNotEmpty(); + } +}