1   /***
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.cli;
18  
19  import junit.framework.Test;
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  public class BuildTest extends TestCase
24  {
25  
26      public static Test suite() { 
27          return new TestSuite(BuildTest.class); 
28      }
29  
30      public BuildTest(String name)
31      {
32          super(name);
33      }
34  
35      public void setUp()
36      {
37  
38      }
39  
40      public void tearDown()
41      {
42  
43      }
44  
45      public void testSimple()
46      {
47          Options opts = new Options();
48          
49          opts.addOption("a",
50                         false,
51                         "toggle -a");
52  
53          opts.addOption("b",
54                         true,
55                         "toggle -b");
56      }
57  
58      public void testDuplicateSimple()
59      {
60          Options opts = new Options();
61          opts.addOption("a",
62                         false,
63                         "toggle -a");
64  
65          opts.addOption("a",
66                         true,
67                         "toggle -a*");
68          
69          assertEquals( "last one in wins", "toggle -a*", opts.getOption("a").getDescription() );
70      }
71  
72      public void testLong()
73      {
74          Options opts = new Options();
75          
76          opts.addOption("a",
77                         "--a",
78                         false,
79                         "toggle -a");
80  
81          opts.addOption("b",
82                         "--b",
83                         true,
84                         "set -b");
85  
86      }
87  
88      public void testDuplicateLong()
89      {
90          Options opts = new Options();
91          opts.addOption("a",
92                         "--a",
93                         false,
94                         "toggle -a");
95  
96          opts.addOption("a",
97                         "--a",
98                         false,
99                         "toggle -a*");
100         assertEquals( "last one in wins", "toggle -a*", opts.getOption("a").getDescription() );
101     }
102 }