1
2
3
4
5 package oshi.hardware;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.containsString;
9 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
10 import static org.hamcrest.Matchers.is;
11 import static org.hamcrest.Matchers.lessThanOrEqualTo;
12 import static org.hamcrest.Matchers.notNullValue;
13
14 import org.junit.jupiter.api.Test;
15
16 import oshi.SystemInfo;
17
18
19
20
21 class VirtualMemoryTest {
22
23
24
25 @Test
26 void testGlobalMemory() {
27 SystemInfo si = new SystemInfo();
28 HardwareAbstractionLayer hal = si.getHardware();
29 GlobalMemory memory = hal.getMemory();
30 VirtualMemory vm = memory.getVirtualMemory();
31 assertThat("VM object shouldn't be null", vm, is(notNullValue()));
32
33
34 assertThat("VM's swap pages in shouldn't be negative", vm.getSwapPagesIn(), is(greaterThanOrEqualTo(0L)));
35 assertThat("VM's swap pages out shouldn't be negative", vm.getSwapPagesOut(), is(greaterThanOrEqualTo(0L)));
36 assertThat("VM's swap total shouldn't be negative", vm.getSwapTotal(), is(greaterThanOrEqualTo(0L)));
37 assertThat("VM's swap used shouldn't be negative", vm.getSwapUsed(), is(greaterThanOrEqualTo(0L)));
38 assertThat("VM's swap used should be less than or equal to VM swap total", vm.getSwapUsed(),
39 is(lessThanOrEqualTo(vm.getSwapTotal())));
40 assertThat("VM's max should be greater than or qual to VM swap total", vm.getVirtualMax() >= vm.getSwapTotal(),
41 is(true));
42 assertThat("VM's virtual in use shouldn't be negative", vm.getVirtualInUse(), is(greaterThanOrEqualTo(0L)));
43 assertThat("VM's toString contains 'Used'", vm.toString(), containsString("Used"));
44 }
45 }