View Javadoc
1   package org.codehaus.plexus.util;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Iterator;
20  
21  import org.junit.jupiter.api.Test;
22  
23  import static org.junit.jupiter.api.Assertions.assertEquals;
24  import static org.junit.jupiter.api.Assertions.assertFalse;
25  import static org.junit.jupiter.api.Assertions.assertTrue;
26  
27  /**
28   * Test Case for Os
29   *
30   * @author herve
31   * @version $Id: $Id
32   * @since 3.4.0
33   */
34  public class OsTest {
35      /**
36       * <p>testUndefinedFamily.</p>
37       */
38      @Test
39      public void testUndefinedFamily() {
40          assertFalse(Os.isFamily("bogus family"));
41      }
42  
43      /**
44       * <p>testOs.</p>
45       */
46      @Test
47      public void testOs() {
48          Iterator<String> iter = Os.getValidFamilies().iterator();
49          String currentFamily = null;
50          String notCurrentFamily = null;
51          while (iter.hasNext() && (currentFamily == null || notCurrentFamily == null)) {
52              String fam = iter.next();
53              if (Os.isFamily(fam)) {
54                  currentFamily = fam;
55              } else {
56                  notCurrentFamily = fam;
57              }
58          }
59  
60          // make sure the OS_FAMILY is set right.
61          assertEquals(currentFamily, Os.OS_FAMILY);
62  
63          // check the current family and one of the others
64          assertTrue(Os.isOs(currentFamily, null, null, null));
65          assertFalse(Os.isOs(notCurrentFamily, null, null, null));
66  
67          // check for junk
68          assertFalse(Os.isOs("junk", null, null, null));
69  
70          // check the current name
71          assertTrue(Os.isOs(currentFamily, Os.OS_NAME, null, null));
72  
73          // check some other name
74          assertFalse(Os.isOs(currentFamily, "myos", null, null));
75  
76          // check the arch
77          assertTrue(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, null));
78          assertFalse(Os.isOs(currentFamily, Os.OS_NAME, "myarch", null));
79  
80          // check the version
81          assertTrue(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, Os.OS_VERSION));
82          assertFalse(Os.isOs(currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion"));
83      }
84  
85      /**
86       * <p>testValidList.</p>
87       */
88      @org.junit.jupiter.api.Test
89      public void testValidList() {
90          assertTrue(Os.isValidFamily("dos"));
91  
92          assertFalse(Os.isValidFamily(""));
93          assertFalse(Os.isValidFamily(null));
94          assertFalse(Os.isValidFamily("something"));
95      }
96  }