View Javadoc
1   /*
2    * Copyright 2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.windows;
6   
7   import static org.hamcrest.MatcherAssert.assertThat;
8   import static org.hamcrest.Matchers.empty;
9   import static org.hamcrest.Matchers.is;
10  import static org.hamcrest.Matchers.not;
11  import static org.junit.jupiter.api.Assertions.assertTrue;
12  
13  import java.util.Map;
14  import java.util.Set;
15  import java.util.stream.Collectors;
16  
17  import org.junit.jupiter.api.Test;
18  import org.junit.jupiter.api.condition.EnabledOnOs;
19  import org.junit.jupiter.api.condition.OS;
20  
21  import com.sun.jna.platform.win32.Guid.GUID;
22  
23  import oshi.util.tuples.Quintet;
24  
25  @EnabledOnOs(OS.WINDOWS)
26  class DeviceTreeTest {
27      private static final GUID GUID_DEVINTERFACE_NET = new GUID("{CAC88484-7515-4C03-82E6-71A87ABAC361}");
28  
29      @Test
30      void testQueryDeviceTree() {
31          Quintet<Set<Integer>, Map<Integer, Integer>, Map<Integer, String>, Map<Integer, String>, Map<Integer, String>> tree = DeviceTree
32                  .queryDeviceTree(GUID_DEVINTERFACE_NET);
33          Set<Integer> rootSet = tree.getA();
34          assertThat("Tree root set must not be empty", rootSet, is(not(empty())));
35          Map<Integer, Integer> parentMap = tree.getB();
36          Set<Integer> branchSet = parentMap.keySet().stream().collect(Collectors.toSet());
37          branchSet.retainAll(rootSet); // intersection
38          assertThat("Branches cannot match root", branchSet, is(empty()));
39          Set<Integer> nodeSet = parentMap.keySet().stream().collect(Collectors.toSet());
40          nodeSet.addAll(rootSet); // union
41  
42          assertTrue(nodeSet.containsAll(tree.getC().keySet()), "Name map should only have nodes as keys");
43          assertTrue(nodeSet.containsAll(tree.getD().keySet()), "Device Id should only have nodes as keys");
44          assertTrue(nodeSet.containsAll(tree.getE().keySet()), "Manufacturer map should only have nodes as keys");
45      }
46  }