View Javadoc
1   /*
2    * Copyright 2021-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.mac;
6   
7   import static org.hamcrest.MatcherAssert.assertThat;
8   import static org.hamcrest.Matchers.emptyOrNullString;
9   import static org.hamcrest.Matchers.greaterThan;
10  import static org.hamcrest.Matchers.is;
11  import static org.hamcrest.Matchers.lessThanOrEqualTo;
12  import static org.hamcrest.Matchers.not;
13  
14  import java.util.HashSet;
15  import java.util.List;
16  import java.util.Set;
17  
18  import org.junit.jupiter.api.Test;
19  import org.junit.jupiter.api.condition.EnabledOnOs;
20  import org.junit.jupiter.api.condition.OS;
21  
22  import oshi.software.os.OSDesktopWindow;
23  
24  @EnabledOnOs(OS.MAC)
25  class WindowInfoTest {
26      @Test
27      void testQueryDesktopWindows() {
28          final List<OSDesktopWindow> osDesktopWindows = WindowInfo.queryDesktopWindows(true);
29          final List<OSDesktopWindow> allOsDesktopWindows = WindowInfo.queryDesktopWindows(false);
30          final Set<Integer> windowOrders = new HashSet<>();
31          final Set<Long> windowIds = new HashSet<>();
32  
33          assertThat("Desktop should have at least one window.", osDesktopWindows.size(), is(greaterThan(0)));
34          assertThat("The number of all desktop windows should be greater than the number of visible desktop windows",
35                  allOsDesktopWindows.size(), is(greaterThan(osDesktopWindows.size())));
36          for (OSDesktopWindow window : osDesktopWindows) {
37              assertThat("Window IDs are not unique.", windowIds.contains(window.getWindowId()), is(false));
38              windowOrders.add(window.getOrder());
39              windowIds.add(window.getWindowId());
40              assertThat("Windows should have a title.", window.getTitle(), is(not(emptyOrNullString())));
41              assertThat("Window should be visible", window.isVisible(), is(true));
42          }
43          assertThat("Number of layers must be less than or equal to 20.", windowOrders.size(),
44                  is(lessThanOrEqualTo(20)));
45      }
46  }