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.is;
10 import static org.hamcrest.Matchers.matchesPattern;
11 import static org.hamcrest.Matchers.notNullValue;
12
13 import java.util.regex.Pattern;
14
15 import org.junit.jupiter.api.Test;
16
17 import oshi.SystemInfo;
18
19
20
21
22 class ComputerSystemTest {
23 private static final Pattern UUID_PATTERN = Pattern
24 .compile("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}|unknown");
25
26
27
28
29 @Test
30 void testComputerSystem() {
31 SystemInfo si = new SystemInfo();
32 ComputerSystem cs = si.getHardware().getComputerSystem();
33 assertThat("Computer System's manufacturer shouldn't be null", cs.getManufacturer(), is(notNullValue()));
34 assertThat("Computer System's model shouldn't be null", cs.getModel(), is(notNullValue()));
35 assertThat("Computer System's serial number shouldn't be null", cs.getSerialNumber(), is(notNullValue()));
36 assertThat("Computer System's UUID should be in UUID format or unknown", cs.getHardwareUUID(),
37 matchesPattern(UUID_PATTERN));
38
39 Firmware fw = cs.getFirmware();
40 assertThat("Firmware shouldn't be null", fw, is(notNullValue()));
41 assertThat("Firmware's manufacturer shouldn't be null", fw.getManufacturer(), is(notNullValue()));
42 assertThat("Firmware's name shouldn't be null", fw.getName(), is(notNullValue()));
43 assertThat("Firmware's description shouldn't be null", fw.getDescription(), is(notNullValue()));
44 assertThat("Firmware's version shouldn't be null", fw.getVersion(), is(notNullValue()));
45 assertThat("Firmware's release date shouldn't be null", fw.getReleaseDate(), is(notNullValue()));
46 assertThat("Firmware's tostring value should contain manufacturer's name", fw.toString(),
47 containsString(fw.getManufacturer()));
48
49 Baseboard bb = cs.getBaseboard();
50 assertThat("Baseboard shouldn't be null", bb, is(notNullValue()));
51 assertThat("Baseboard's manufacturer shouldn't be null", bb.getManufacturer(), is(notNullValue()));
52 assertThat("Baseboard's model shouldn't be null", bb.getModel(), is(notNullValue()));
53 assertThat("Baseboard's version shouldn't be null", bb.getVersion(), is(notNullValue()));
54 assertThat("Baseboard's serial number shouldn't be null", bb.getSerialNumber(), is(notNullValue()));
55 }
56 }