1
2
3
4
5 package oshi.hardware;
6
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.closeTo;
9 import static org.hamcrest.Matchers.either;
10 import static org.hamcrest.Matchers.greaterThan;
11 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
12 import static org.hamcrest.Matchers.is;
13
14 import java.util.List;
15
16 import org.junit.jupiter.api.Test;
17
18 import oshi.SystemInfo;
19
20
21
22
23 class PowerSourceTest {
24
25
26
27 @Test
28 void testPowerSource() {
29 SystemInfo si = new SystemInfo();
30 List<PowerSource> psArr = si.getHardware().getPowerSources();
31 for (PowerSource ps : psArr) {
32 assertThat("Power Source's remaining capacity shouldn't be negative", ps.getRemainingCapacityPercent(),
33 is(greaterThanOrEqualTo(0d)));
34 double epsilon = 1E-6;
35 assertThat(
36 "Power Source's estimated remaining time should be greater than zero or within error margin of -1 or within error margin of -2",
37 ps.getTimeRemainingEstimated(),
38 is(either(greaterThan(0d)).or(closeTo(-1d, epsilon)).or(closeTo(-2d, epsilon))));
39 }
40 }
41 }