Skip to content

Commit 1f27c9d

Browse files
shouvikbhattacharyapivovarit
authored andcommitted
BAEL-1534: Detect the OS from Java (eugenp#3636)
* BAEL-1534: Mini-article completed. * BAEL-1534: Changes incorporated. * BAEL-1534: Changes incorporated. * BAEL-1534: Changes incorporated. * BAEL-1534: Changes incorporated.
1 parent 487864a commit 1f27c9d

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.system;
2+
3+
import org.apache.commons.lang3.SystemUtils;
4+
5+
public class DetectOS {
6+
7+
public String getOperatingSystem() {
8+
String os = System.getProperty("os.name");
9+
System.out.println("Using System Property: " + os);
10+
return os;
11+
}
12+
13+
public String getOperatingSystemSystemUtils() {
14+
String os = SystemUtils.OS_NAME;
15+
System.out.println("Using SystemUtils: " + os);
16+
return os;
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.system;
2+
3+
import org.junit.Assert;
4+
import org.junit.Ignore;
5+
import org.junit.Test;
6+
7+
@Ignore
8+
public class WhenDetectingOSTest {
9+
10+
private DetectOS os = new DetectOS();
11+
12+
@Test
13+
public void whenUsingSystemProperty_shouldReturnOS() {
14+
String expected = "Windows 10";
15+
String actual = os.getOperatingSystem();
16+
Assert.assertEquals(expected, actual);
17+
}
18+
19+
@Test
20+
public void whenUsingSystemUtils_shouldReturnOS() {
21+
String expected = "Windows 10";
22+
String actual = os.getOperatingSystemSystemUtils();
23+
Assert.assertEquals(expected, actual);
24+
}
25+
}

0 commit comments

Comments
 (0)