1
2
3
4
5 package oshi.hardware;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.both;
9 import static org.hamcrest.Matchers.containsString;
10 import static org.hamcrest.Matchers.greaterThan;
11 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
12 import static org.hamcrest.Matchers.is;
13 import static org.hamcrest.Matchers.lessThanOrEqualTo;
14 import static org.hamcrest.Matchers.notNullValue;
15
16 import java.util.List;
17
18 import org.junit.jupiter.api.BeforeAll;
19 import org.junit.jupiter.api.Test;
20 import org.junit.jupiter.api.TestInstance;
21 import org.junit.jupiter.api.TestInstance.Lifecycle;
22
23 import oshi.SystemInfo;
24
25
26
27
28 @TestInstance(Lifecycle.PER_CLASS)
29 class GlobalMemoryTest {
30 private GlobalMemory memory = null;
31
32 @BeforeAll
33 void setUp() {
34 SystemInfo si = new SystemInfo();
35 HardwareAbstractionLayer hal = si.getHardware();
36 this.memory = hal.getMemory();
37 }
38
39 @Test
40 void testGlobalMemory() {
41 assertThat("Memory shouldn't be null", memory, is(notNullValue()));
42 assertThat("Total memory should be greater than zero", memory.getTotal(), is(greaterThan(0L)));
43 assertThat("Available memory should be between 0 and total memory", memory.getAvailable(),
44 is(both(greaterThanOrEqualTo(0L)).and(lessThanOrEqualTo(memory.getTotal()))));
45 assertThat("Memory page size should be greater than zero", memory.getPageSize(), is(greaterThan(0L)));
46 assertThat("Memory toString should contain the substring \"Available\"", memory.toString(),
47 containsString("Available"));
48 }
49
50 @Test
51 void testPhysicalMemory() {
52 List<PhysicalMemory> pm = memory.getPhysicalMemory();
53 for (PhysicalMemory m : pm) {
54 assertThat("Bank label shouldn't be null", m.getBankLabel(), is(notNullValue()));
55 assertThat("Capacity should be nonnegative", m.getCapacity(), is(greaterThanOrEqualTo(0L)));
56 assertThat("Speed should be nonnegative or -1", m.getClockSpeed(), is(greaterThanOrEqualTo(-1L)));
57 assertThat("Manufacturer shouldn't be null", m.getManufacturer(), is(notNullValue()));
58 assertThat("Memory type shouldn't be null", m.getMemoryType(), is(notNullValue()));
59 assertThat("Part number shouldn't be null", m.getPartNumber(), is(notNullValue()));
60 }
61 }
62 }