View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.model;
12  
13  import static org.junit.jupiter.api.Assertions.assertNotNull;
14  import static org.junit.jupiter.api.Assertions.assertTrue;
15  
16  import com.codebox.bean.JavaBeanTester;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.junit.jupiter.api.Test;
22  
23  /**
24   * The Class SystemInformationTest.
25   */
26  class SystemInformationTest {
27  
28    /**
29     * Javabean tester.
30     */
31    @Test
32    void javabeanTester() {
33      JavaBeanTester.builder(SystemInformation.class).loadData().skipStrictSerializable().test();
34    }
35  
36    @Test
37    void testGetMemoryValues() {
38      SystemInformation si = new SystemInformation();
39      assertTrue(si.getMaxMemory() > 0);
40      assertTrue(si.getFreeMemory() >= 0);
41      assertTrue(si.getTotalMemory() > 0);
42    }
43  
44    @Test
45    void testGetCpuCount() {
46      SystemInformation si = new SystemInformation();
47      assertTrue(si.getCpuCount() > 0);
48    }
49  
50    @Test
51    void testGetDate() {
52      SystemInformation si = new SystemInformation();
53      assertNotNull(si.getDate());
54    }
55  
56    @Test
57    void testGetWorkingDir() {
58      SystemInformation si = new SystemInformation();
59      assertNotNull(si.getWorkingDir());
60    }
61  
62    @Test
63    void testGetServerInfo() {
64      SystemInformation si = new SystemInformation();
65      // may return empty string if not in Tomcat, but should not throw
66      assertNotNull(si.getServerInfo());
67    }
68  
69    @Test
70    void testSystemPropertySet() {
71      SystemInformation si = new SystemInformation();
72      Map<String, String> props = new HashMap<>();
73      props.put("key1", "val1");
74      si.setSystemProperties(props);
75      assertNotNull(si.getSystemPropertySet());
76      assertTrue(si.getSystemPropertySet().size() == 1);
77    }
78  }