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
15
16
17
18
19
20
21
22
23
24
25
26
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 }