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:
parent
487864a2f2
commit
1f27c9ded7
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue