1   package com.lexicalscope.jewel.cli.examples;
2   
3   import static org.hamcrest.MatcherAssert.assertThat;
4   import static org.hamcrest.Matchers.*;
5   
6   import java.util.List;
7   
8   import org.junit.Test;
9   
10  import com.lexicalscope.jewel.cli.CliFactory;
11  import com.lexicalscope.jewel.cli.Option;
12  
13  /*
14   * Copyright 2011 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 TestEnumOptionExample {
30      public enum ExampleEnum {
31          Value1, Value2, Value3
32      }
33  
34      interface EnumOptionExample
35      {
36          @Option ExampleEnum getOptionOne();
37          boolean isOptionOne();
38  
39          @Option List<ExampleEnum> getOptionTwo();
40          boolean isOptionTwo();
41      }
42  
43      @Test public void specifiedSingleValueEnumOptionGivesEnumValue() {
44          final EnumOptionExample cli =
45                  CliFactory.parseArguments(EnumOptionExample.class, "--optionOne", "Value2");
46  
47          assertThat(cli.getOptionOne(), equalTo(ExampleEnum.Value2));
48      }
49  
50      @Test public void specifiedMultivaluedEnumOptionGivesListOfEnumValues() {
51          final EnumOptionExample cli =
52                  CliFactory.parseArguments(EnumOptionExample.class, "--optionTwo", "Value1", "Value3");
53  
54          assertThat(cli.getOptionTwo(), hasItems(ExampleEnum.Value1, ExampleEnum.Value3));
55      }
56  }