View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.software.os;
6   
7   import org.junit.jupiter.api.Test;
8   import oshi.PlatformEnum;
9   import oshi.SystemInfo;
10  
11  import static org.hamcrest.MatcherAssert.assertThat;
12  import static org.hamcrest.Matchers.is;
13  import static org.hamcrest.Matchers.notNullValue;
14  import static org.hamcrest.Matchers.greaterThanOrEqualTo;
15  
16  /**
17   * Test File System
18   */
19  class FileSystemTest {
20  
21      /**
22       * Test file system.
23       *
24       */
25      @Test
26      void testFileSystem() {
27          SystemInfo si = new SystemInfo();
28          FileSystem filesystem = si.getOperatingSystem().getFileSystem();
29          assertThat("File system open file descriptors should be 0 or higher", filesystem.getOpenFileDescriptors(),
30                  greaterThanOrEqualTo(0L));
31          assertThat("File system max open file descriptors should be 0 or higher", filesystem.getMaxFileDescriptors(),
32                  greaterThanOrEqualTo(0L));
33          assertThat("File system max open file descriptors per process should be 0 or higher",
34                  filesystem.getMaxFileDescriptorsPerProcess(), greaterThanOrEqualTo(0L));
35          filesystem.getMaxFileDescriptorsPerProcess();
36          for (OSFileStore store : filesystem.getFileStores()) {
37              assertThat("File store name shouldn't be null", store.getName(), is(notNullValue()));
38              assertThat("File store volume shouldn't be null", store.getVolume(), is(notNullValue()));
39              assertThat("File store label shouldn't be null", store.getLabel(), is(notNullValue()));
40              assertThat("File store logical volume shouldn't be null", store.getLogicalVolume(), is(notNullValue()));
41              assertThat("File store description shouldn't be null", store.getDescription(), is(notNullValue()));
42              assertThat("File store type shouldn't be null", store.getType(), is(notNullValue()));
43              assertThat("File store options shouldn't be empty", store.getOptions().isEmpty(), is(false));
44              assertThat("File store mount shouldn't be null", store.getMount(), is(notNullValue()));
45              assertThat("File store UUID shouldn't be null", store.getUUID(), is(notNullValue()));
46              assertThat("File store total space should be 0 or higher", store.getTotalSpace() >= 0, is(true));
47              assertThat("File store usable space should be 0 or higher", store.getUsableSpace() >= 0, is(true));
48              assertThat("File store free space should be 0 or higher", store.getFreeSpace() >= 0, is(true));
49              if (SystemInfo.getCurrentPlatform() != PlatformEnum.WINDOWS) {
50                  assertThat("Number of free inodes should be 0 or higher on non-Windows systems",
51                          store.getFreeInodes() >= 0, is(true));
52                  if (SystemInfo.getCurrentPlatform() != PlatformEnum.SOLARIS) {
53                      assertThat(
54                              "Total number of inodes should be greater than or equal to number of free inodes on non-Windows/Solaris systems",
55                              store.getTotalInodes() >= store.getFreeInodes(), is(true));
56                  }
57              }
58              if (!store.getDescription().equals("Network drive")) {
59                  assertThat(
60                          "File store's usable space should be less than or equal to the total space on non-network drives",
61                          store.getUsableSpace() <= store.getTotalSpace(), is(true));
62              }
63          }
64      }
65  }