1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.cli2;
18
19 import org.apache.commons.cli2.option.ArgumentTest;
20 import org.apache.commons.cli2.option.PropertyOption;
21
22
23
24
25 public abstract class WriteableCommandLineTestCase extends CommandLineTestCase {
26
27 private WriteableCommandLine writeable;
28
29 protected abstract WriteableCommandLine createWriteableCommandLine();
30
31
32
33
34 protected final CommandLine createCommandLine() {
35 final WriteableCommandLine cl = createWriteableCommandLine();
36 cl.addOption(present);
37 cl.addProperty(new PropertyOption(), "present","present property");
38 cl.addSwitch(bool,true);
39 cl.addValue(present,"present value");
40 cl.addOption(multiple);
41 cl.addValue(multiple,"value 1");
42 cl.addValue(multiple,"value 2");
43 cl.addValue(multiple,"value 3");
44 return cl;
45 }
46
47
48
49
50 public void setUp() throws Exception {
51 super.setUp();
52 writeable = createWriteableCommandLine();
53 }
54 public final void testAddOption() {
55 assertFalse(writeable.hasOption(present));
56 writeable.addOption(present);
57 assertTrue(writeable.hasOption(present));
58 }
59 public final void testAddValue() {
60 assertFalse(writeable.hasOption(present));
61 assertTrue(writeable.getValues(present).isEmpty());
62 writeable.addValue(present,"value");
63 assertContentsEqual(list("value"),writeable.getValues(present));
64
65
66 assertFalse(writeable.hasOption(present));
67
68 final Argument arg = ArgumentTest.buildHostArgument();
69
70 assertFalse(writeable.hasOption(arg));
71 assertTrue(writeable.getValues(arg).isEmpty());
72 writeable.addValue(arg,"value");
73 assertContentsEqual(list("value"),writeable.getValues(arg));
74
75
76 assertTrue(writeable.hasOption(arg));
77 }
78 public final void testAddSwitch() {
79 assertFalse(writeable.hasOption(present));
80 assertNull(writeable.getSwitch(present));
81 writeable.addSwitch(present,true);
82 assertEquals(Boolean.TRUE,writeable.getSwitch(present));
83 assertTrue(writeable.hasOption(present));
84 }
85 public final void testAddProperty() {
86 assertNull(writeable.getProperty(new PropertyOption(), "present"));
87 writeable.addProperty(new PropertyOption(), "present","present value");
88 assertEquals("present value",writeable.getProperty(new PropertyOption(), "present"));
89 }
90 public final void testLooksLikeOption() {
91
92 }
93 }