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 junit.framework.TestCase;
22  
23  /**
24   * Test Case for Os
25   */
26  public class OsTest
27      extends TestCase
28  {
29      public void testUndefinedFamily()
30      {
31          assertFalse( Os.isFamily( "bogus family" ) );
32      }
33  
34      public void testOs()
35      {
36          Iterator<String> iter = Os.getValidFamilies().iterator();
37          String currentFamily = null;
38          String notCurrentFamily = null;
39          while ( iter.hasNext() && ( currentFamily == null || notCurrentFamily == null ) )
40          {
41              String fam = iter.next();
42              if ( Os.isFamily( fam ) )
43              {
44                  currentFamily = fam;
45              }
46              else
47              {
48                  notCurrentFamily = fam;
49              }
50          }
51  
52          // make sure the OS_FAMILY is set right.
53          assertEquals( currentFamily, Os.OS_FAMILY );
54  
55          // check the current family and one of the others
56          assertTrue( Os.isOs( currentFamily, null, null, null ) );
57          assertFalse( Os.isOs( notCurrentFamily, null, null, null ) );
58  
59          // check for junk
60          assertFalse( Os.isOs( "junk", null, null, null ) );
61  
62          // check the current name
63          assertTrue( Os.isOs( currentFamily, Os.OS_NAME, null, null ) );
64  
65          // check some other name
66          assertFalse( Os.isOs( currentFamily, "myos", null, null ) );
67  
68          // check the arch
69          assertTrue( Os.isOs( currentFamily, Os.OS_NAME, Os.OS_ARCH, null ) );
70          assertFalse( Os.isOs( currentFamily, Os.OS_NAME, "myarch", null ) );
71  
72          // check the version
73          assertTrue( Os.isOs( currentFamily, Os.OS_NAME, Os.OS_ARCH, Os.OS_VERSION ) );
74          assertFalse( Os.isOs( currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion" ) );
75      }
76  
77      public void testValidList()
78      {
79          assertTrue( Os.isValidFamily( "dos" ) );
80  
81          assertFalse( Os.isValidFamily( "" ) );
82          assertFalse( Os.isValidFamily( null ) );
83          assertFalse( Os.isValidFamily( "something" ) );
84      }
85  }