01: /*
02: Copyright 2004-2007 Paul R. Holser, Jr. All rights reserved.
03: Licensed under the Academic Free License version 3.0
04: */
05:
06: package joptsimple;
07:
08: import java.util.Collections;
09:
10: /**
11: * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
12: * @version $Id: LongOptionRequiredArgumentTest.java,v 1.15 2007/04/10 20:06:26 pholser Exp $
13: */
14: public class LongOptionRequiredArgumentTest extends
15: AbstractOptionParserFixture {
16: protected void setUp() throws Exception {
17: super .setUp();
18:
19: parser.accepts("quiet").withRequiredArg();
20: parser.accepts("a").withOptionalArg();
21: parser.accepts("y").withRequiredArg();
22: }
23:
24: public void testArgumentSeparate() {
25: OptionSet options = parser
26: .parse(new String[] { "--quiet", "23" });
27: assertOptionDetected(options, "quiet");
28: assertEquals(Collections.singletonList("23"), options
29: .argumentsOf("quiet"));
30: assertEquals(Collections.EMPTY_LIST, options
31: .nonOptionArguments());
32: }
33:
34: public void testArgumentFollowedByLegalOption() {
35: OptionSet options = parser
36: .parse(new String[] { "--quiet", "-a" });
37: assertOptionDetected(options, "quiet");
38: assertOptionNotDetected(options, "a");
39: assertEquals(Collections.singletonList("-a"), options
40: .argumentsOf("quiet"));
41: assertEquals(Collections.EMPTY_LIST, options
42: .nonOptionArguments());
43: }
44:
45: public void testArgumentTogether() {
46: OptionSet options = parser.parse(new String[] { "--quiet=23" });
47: assertOptionDetected(options, "quiet");
48: assertEquals(Collections.singletonList("23"), options
49: .argumentsOf("quiet"));
50: assertEquals(Collections.EMPTY_LIST, options
51: .nonOptionArguments());
52: }
53:
54: public void testArgumentMissing() {
55: try {
56: parser.parse(new String[] { "--quiet" });
57: fail();
58: } catch (OptionMissingRequiredArgumentException expected) {
59: assertEquals("quiet", expected.option());
60: }
61: }
62:
63: public void testShortOptionSpecifiedAsLongOptionWithArgument() {
64: OptionSet options = parser.parse(new String[] { "--y=bar" });
65: assertOptionDetected(options, "y");
66: assertEquals(Collections.singletonList("bar"), options
67: .argumentsOf("y"));
68: assertEquals(Collections.EMPTY_LIST, options
69: .nonOptionArguments());
70: }
71: }
|