1 package org.kohsuke.args4j;
2
3 import java.util.Map;
4
5 public class PropsTest extends Args4JTestBase {
6
7 @Override
8 public Object getTestObject() {
9 return new Props();
10 }
11
12 public void testDoNothing() {
13
14
15 }
16
17 public void _testNoValues() {
18 args = new String[]{};
19 try {
20 parser.parseArgument(args);
21 Map map = ((Props)testObject).props;
22 assertTrue("Values illegally arrived.", map.size()==0);
23 } catch (CmdLineException e) {
24 fail("Call without parameters is valid!");
25 }
26 }
27
28 public void _testSinglePair() {
29 args = new String[]{"-Tkey1=value1"};
30 try {
31 parser.parseArgument(args);
32 Map map = ((Props)testObject).props;
33 assertTrue("The key was not set.", map.containsKey("key1"));
34 assertEquals("More keys than expected.", map.size(), 1);
35 assertEquals("Key has wrong value", map.get("key1"), "value1");
36 } catch (CmdLineException e) {
37 fail("Cought an invalid exception");
38 }
39 }
40
41 public void _testMultiplePairs() {
42 args = new String[]{"-Tkey1=value1", "-Tkey2=value2", "-Tkey3=value3"};
43 try {
44 parser.parseArgument(args);
45 Map map = ((Props)testObject).props;
46 assertTrue("A key was not set.", map.containsKey("key1"));
47 assertTrue("A key was not set.", map.containsKey("key2"));
48 assertTrue("A key was not set.", map.containsKey("key3"));
49 assertEquals("Wrong number of keys.", map.size(), 3);
50 assertEquals("Key has wrong value", map.get("key1"), "value1");
51 assertEquals("Key has wrong value", map.get("key2"), "value2");
52 assertEquals("Key has wrong value", map.get("key3"), "value3");
53 } catch (CmdLineException e) {
54 fail("Cought an invalid exception");
55 }
56 }
57
58 public void _testDuplicateKey() {
59 args = new String[]{"-Tkey1=value1", "-Tkey1=value1"};
60 try {
61 parser.parseArgument(args);
62 Map map = ((Props)testObject).props;
63 assertTrue("A key was not set.", map.containsKey("key1"));
64 assertEquals("Wrong number of keys.", map.size(), 1);
65
66 } catch (CmdLineException e) {
67
68 }
69 }
70 }