View Javadoc

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.cli2.bug;
18  
19  import java.io.PrintWriter;
20  import java.io.StringWriter;
21  
22  import org.apache.commons.cli2.Group;
23  import org.apache.commons.cli2.Option;
24  import org.apache.commons.cli2.builder.DefaultOptionBuilder;
25  import org.apache.commons.cli2.builder.GroupBuilder;
26  import org.apache.commons.cli2.util.HelpFormatter;
27  
28  import junit.framework.TestCase;
29  
30  /**
31   * http://issues.apache.org/jira/browse/CLI-18
32   */
33  public class BugCLI18Test extends TestCase {
34  
35    public BugCLI18Test() {
36      super();
37    }
38  
39  
40    public void testBug() {
41      Option a = new DefaultOptionBuilder().withLongName("aaa").withShortName("a").withDescription("aaaaaaa").create();
42      Option b = new DefaultOptionBuilder().withLongName("bbb").withDescription("bbbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f").create();
43      Option c = new DefaultOptionBuilder().withLongName("ccc").withShortName("c").withDescription("ccccccc").create();
44  
45      Group g = new GroupBuilder().withOption(a).withOption(b).withOption(c).create();
46  
47      HelpFormatter formatter = new HelpFormatter();
48      StringWriter out = new StringWriter();
49  
50      formatter.setPrintWriter(new PrintWriter(out));
51      formatter.setHeader("dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s");
52      formatter.setFooter("blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr");
53      formatter.setGroup(g);
54      formatter.setShellCommand("foobar");
55  
56      formatter.print();
57  
58    }
59  }
60