1
2
3
4
5 package oshi.util;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.anEmptyMap;
9 import static org.hamcrest.Matchers.emptyString;
10 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
11 import static org.hamcrest.Matchers.is;
12 import static org.hamcrest.Matchers.not;
13
14 import org.junit.jupiter.api.Test;
15
16 import oshi.PlatformEnum;
17 import oshi.SystemInfo;
18 import oshi.util.platform.unix.freebsd.ProcstatUtil;
19
20
21
22
23 class ProcstatUtilTest {
24
25 @Test
26 void testProcstat() {
27 if (SystemInfo.getCurrentPlatform().equals(PlatformEnum.FREEBSD)) {
28 int pid = new SystemInfo().getOperatingSystem().getProcessId();
29
30 assertThat("Open files must be nonnegative", ProcstatUtil.getOpenFiles(pid), is(greaterThanOrEqualTo(0L)));
31
32 assertThat("CwdMap should have at least one element", ProcstatUtil.getCwdMap(-1), is(not(anEmptyMap())));
33
34 assertThat("CwdMap with pid should have at least one element", ProcstatUtil.getCwdMap(pid),
35 is(not(anEmptyMap())));
36
37 assertThat("Cwd should be nonempty", ProcstatUtil.getCwd(pid), is(not(emptyString())));
38 }
39 }
40 }