1   package com.lexicalscope.jewel.cli.examples;
2   
3   import static com.lexicalscope.jewel.cli.CliFactory.*;
4   import static org.hamcrest.MatcherAssert.assertThat;
5   import static org.hamcrest.Matchers.equalTo;
6   
7   import org.junit.Test;
8   
9   import com.lexicalscope.jewel.cli.Option;
10  
11  /*
12   * Copyright 2012 Tim Wood
13   *
14   * Licensed under the Apache License, Version 2.0 (the "License");
15   * you may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at
17   *
18   * http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   */
26  
27  public class TestOptionsWithoutGetPrefix {
28      public interface InterfaceWithNoGetPrefix {
29          @Option String name();
30      }
31  
32      public static class ClassWithNoGetPrefix {
33          private String name;
34  
35          public String name()
36          {
37              return name;
38          }
39  
40          @Option public void name(final String name)
41          {
42              this.name = name;
43          }
44      }
45  
46      @Test public void interfaceOptionsWithoutGetPrefixWork()
47      {
48          assertThat(parseArguments(InterfaceWithNoGetPrefix.class, "--name", "value").name(), equalTo("value"));
49      }
50  
51      @Test public void classOptionsWithoutGetPrefixWork()
52      {
53          assertThat(parseArgumentsUsingInstance(new ClassWithNoGetPrefix(), "--name", "value").name(), equalTo("value"));
54      }
55  }