View Javadoc
1   package org.codehaus.plexus.tools.cli;
2   
3   /*
4    * Copyright 2006 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 org.codehaus.plexus.PlexusTestCase;
20  import org.codehaus.plexus.util.FileUtils;
21  
22  import java.lang.reflect.Method;
23  import java.lang.reflect.Modifier;
24  import java.io.File;
25  
26  /**
27   * @author Jason van Zyl
28   */
29  public class CliTest
30      extends PlexusTestCase
31  {
32      public void testCli()
33          throws Exception
34      {
35          String[] args = new String[]{"-n", getBasedir()};
36  
37          Class clazz = TestCli.class;
38  
39          Method m = clazz.getMethod( "main", new Class[]{String[].class} );
40  
41          int modifiers = m.getModifiers();
42  
43          if ( Modifier.isStatic( modifiers ) && Modifier.isPublic( modifiers ) )
44          {
45              if ( m.getReturnType() == Integer.TYPE || m.getReturnType() == Void.TYPE )
46              {
47                  m.invoke( clazz, new Object[]{args} );
48              }
49          }
50  
51          String s = FileUtils.fileRead( new File( getBasedir(), "target/cli.txt" ) );
52  
53          assertEquals( "NAME_OPTION_INVOKED", s );
54      }
55  }