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.containsString;
6   
7   import org.junit.Test;
8   
9   import com.lexicalscope.jewel.cli.CommandLineInterface;
10  import com.lexicalscope.jewel.cli.Option;
11  import com.lexicalscope.jewel.cli.OptionOrder;
12  
13  /*
14   * Copyright 2012 Tim Wood
15   *
16   * Licensed under the Apache License, Version 2.0 (the "License");
17   * you may not use this file except in compliance with the License.
18   * You may obtain a copy of the License at
19   *
20   * http://www.apache.org/licenses/LICENSE-2.0
21   *
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an "AS IS" BASIS,
24   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25   * See the License for the specific language governing permissions and
26   * limitations under the License.
27   */
28  
29  public class TestHelpMessageOrder {
30      interface LexicographicOrder
31      {
32          @Option
33          int getB();
34  
35          @Option
36          int getA();
37  
38          @Option(helpRequest = true)
39          boolean getHelp();
40      }
41  
42      @CommandLineInterface(order = OptionOrder.DEFINITION)
43      interface DefinitionOrder
44      {
45          @Option
46          int getB();
47  
48          @Option
49          int getA();
50  
51          @Option(helpRequest = true)
52          boolean getHelp();
53      }
54  
55      @Test public void lexicographicOrderSupported()
56      {
57          assertThat(createCli(LexicographicOrder.class).getHelpMessage(), containsString(String.format("%s%n\t%s", "--a value", "--b value")));
58      }
59  
60      @Test public void definitionOrderSupported()
61      {
62      	// in recent versions of the JDK, definition order is unreliable
63          assertThat(createCli(DefinitionOrder.class).getHelpMessage(), containsString("--a value"));
64          assertThat(createCli(DefinitionOrder.class).getHelpMessage(), containsString("--b value"));
65      }
66  }