1   package com.lexicalscope.jewel.cli.examples;
2   
3   import static com.lexicalscope.jewel.cli.CliFactory.createCli;
4   import static org.hamcrest.MatcherAssert.assertThat;
5   import static org.hamcrest.Matchers.*;
6   
7   import org.junit.Test;
8   
9   import com.lexicalscope.jewel.cli.Option;
10  import com.lexicalscope.jewel.cli.Unparsed;
11  
12  /*
13   * Copyright 2012 Tim Wood
14   *
15   * Licensed under the Apache License, Version 2.0 (the "License");
16   * you may not use this file except in compliance with the License.
17   * You may obtain a copy of the License at
18   *
19   * http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS,
23   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24   * See the License for the specific language governing permissions and
25   * limitations under the License.
26   */
27  
28  public class TestHelpMessages {
29      interface OptionWithDefault
30      {
31          @Option(defaultValue = "3")
32          int getMyOption();
33  
34          @Option(helpRequest = true)
35          boolean getHelp();
36      }
37  
38      @Test public void optionWithDefaultShowAsOptional()
39      {
40          assertThat(createCli(OptionWithDefault.class).getHelpMessage(), containsString("[--myOption value]"));
41      }
42  
43      interface HiddenOptionNotIncludedInHelp
44      {
45          @Option(hidden = true)
46          int getMyOption();
47      }
48  
49      @Test public void hiddenOptionNotIncludedInHelp()
50      {
51          assertThat(createCli(HiddenOptionNotIncludedInHelp.class).getHelpMessage(), not(containsString("myOption")));
52      }
53  
54      interface HiddenUnparsedOptionNotIncludedInHelp
55      {
56          @Unparsed(hidden = true)
57          int getMyOption();
58      }
59  
60      @Test public void hiddenUnparsedOptionNotIncludedInHelp()
61      {
62          assertThat(createCli(HiddenUnparsedOptionNotIncludedInHelp.class).getHelpMessage(), not(containsString("ARGUMENTS")));
63      }
64  }