View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
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.either;
10  import static org.hamcrest.Matchers.greaterThanOrEqualTo;
11  import static org.hamcrest.Matchers.is;
12  import static org.hamcrest.Matchers.lessThanOrEqualTo;
13  import static org.hamcrest.Matchers.notANumber;
14  
15  import org.junit.jupiter.api.Test;
16  
17  import oshi.SystemInfo;
18  
19  /**
20   * Test Sensors
21   */
22  class SensorsTest {
23      private SystemInfo si = new SystemInfo();
24      private Sensors s = si.getHardware().getSensors();
25  
26      /**
27       * Test sensors
28       */
29      @Test
30      void testSensors() {
31          assertThat("CPU Temperature should be NaN or between 0 and 100", s.getCpuTemperature(),
32                  either(notANumber()).or(both(greaterThanOrEqualTo(0d)).and(lessThanOrEqualTo(100d))));
33          assertThat("CPU voltage shouldn't be negative", s.getCpuVoltage(), is(greaterThanOrEqualTo(0d)));
34      }
35  
36      @Test
37      void testFanSpeeds() {
38          int[] speeds = s.getFanSpeeds();
39          for (int speed : speeds) {
40              assertThat("Fan Speed shouldn't be negative", speed, is(greaterThanOrEqualTo(0)));
41          }
42      }
43  }