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.lessThan;
12  import static org.hamcrest.Matchers.not;
13  
14  import org.junit.jupiter.api.Test;
15  import org.junit.jupiter.api.condition.EnabledOnOs;
16  import org.junit.jupiter.api.condition.OS;
17  
18  import oshi.software.os.OSSession;
19  
20  @EnabledOnOs(OS.MAC)
21  class WhoTest {
22      @Test
23      void testQueryUtxent() {
24          for (OSSession session : Who.queryUtxent()) {
25              assertThat("Session login time should be greater than 0", session.getLoginTime(), is(greaterThan(0L)));
26              assertThat("Session login time should be less than current time", session.getLoginTime(),
27                      is(lessThan(System.currentTimeMillis())));
28              assertThat("User should be non-empty", session.getUserName(), is(not(emptyOrNullString())));
29              assertThat("Devices should be non-empty", session.getTerminalDevice(), is(not(emptyOrNullString())));
30          }
31      }
32  }