BAEL-1534: Detect the OS from Java (#3636)

* BAEL-1534: Mini-article completed.

* BAEL-1534: Changes incorporated.

* BAEL-1534: Changes incorporated.

* BAEL-1534: Changes incorporated.

* BAEL-1534: Changes incorporated.
This commit is contained in:
Shouvik Bhattacharya 2018-02-26 11:43:27 +05:30 committed by Grzegorz Piwowarek
parent 487864a2f2
commit 1f27c9ded7
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package com.baeldung.system;
import org.apache.commons.lang3.SystemUtils;
public class DetectOS {
public String getOperatingSystem() {
String os = System.getProperty("os.name");
System.out.println("Using System Property: " + os);
return os;
}
public String getOperatingSystemSystemUtils() {
String os = SystemUtils.OS_NAME;
System.out.println("Using SystemUtils: " + os);
return os;
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.system;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class WhenDetectingOSTest {
private DetectOS os = new DetectOS();
@Test
public void whenUsingSystemProperty_shouldReturnOS() {
String expected = "Windows 10";
String actual = os.getOperatingSystem();
Assert.assertEquals(expected, actual);
}
@Test
public void whenUsingSystemUtils_shouldReturnOS() {
String expected = "Windows 10";
String actual = os.getOperatingSystemSystemUtils();
Assert.assertEquals(expected, actual);
}
}