1   package com.lexicalscope.jewel.cli.examples;
2   
3   import static org.junit.Assert.assertTrue;
4   
5   import org.junit.Test;
6   
7   import com.lexicalscope.jewel.cli.CliFactory;
8   import com.lexicalscope.jewel.cli.Option;
9   
10  /*
11   * Copyright 2011 Tim Wood
12   *
13   * Licensed under the Apache License, Version 2.0 (the "License");
14   * you may not use this file except in compliance with the License.
15   * You may obtain a copy of the License at
16   *
17   * http://www.apache.org/licenses/LICENSE-2.0
18   *
19   * Unless required by applicable law or agreed to in writing, software
20   * distributed under the License is distributed on an "AS IS" BASIS,
21   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22   * See the License for the specific language governing permissions and
23   * limitations under the License. 
24   */
25  
26  public class TestBooleanOptionExample {
27      interface BooleanOptionExample
28      {
29          @Option boolean getOptionOne();
30  
31          @Option Boolean getOptionTwo();
32      }
33  
34      @Test public void specifiedBooleanOptionsReturnTrue() {
35          final BooleanOptionExample cli =
36                  CliFactory.parseArguments(BooleanOptionExample.class, "--optionOne", "--optionTwo");
37  
38          assertTrue("option one is present", cli.getOptionOne());
39          assertTrue("option two is present", cli.getOptionTwo());
40      }
41  
42      @Test public void omittedBooleanOptionsReturnFalse() {
43          final BooleanOptionExample cli =
44                  CliFactory.parseArguments(BooleanOptionExample.class);
45  
46          assertTrue("option one is not present", !cli.getOptionOne());
47          assertTrue("option two is not present", !cli.getOptionTwo());
48      }
49  }