1 package com.beust.jcommander.dynamic;
2 
3 import com.beust.jcommander.JCommander;
4 import com.beust.jcommander.ParameterException;
5 import com.beust.jcommander.internal.Maps;
6 
7 import org.testng.Assert;
8 import org.testng.annotations.Test;
9 
10 @Test
11 public class DynamicParameterTest {
12 
13   @Test(expectedExceptions = ParameterException.class)
nonMapShouldThrow()14   public void nonMapShouldThrow() {
15     new JCommander(new DSimpleBad()).parse("-D", "a=b", "-D", "c=d");
16   }
17 
18   @Test(expectedExceptions = ParameterException.class)
wrongSeparatorShouldThrow()19   public void wrongSeparatorShouldThrow() {
20     DSimple ds = new DSimple();
21     new JCommander(ds).parse("-D", "a:b", "-D", "c=d");
22   }
23 
simple(String... parameters)24   private void simple(String... parameters) {
25     DSimple ds = new DSimple();
26     new JCommander(ds).parse(parameters);
27     Assert.assertEquals(ds.params, Maps.newHashMap("a", "b", "c", "d"));
28   }
29 
simpleWithSpaces()30   public void simpleWithSpaces() {
31     simple("-D", "a=b", "-D", "c=d");
32   }
33 
simpleWithoutSpaces()34   public void simpleWithoutSpaces() {
35     simple("-Da=b", "-Dc=d");
36   }
37 
usage()38   public void usage() {
39     DSimple ds = new DSimple();
40     new JCommander(ds).usage(new StringBuilder());
41   }
42 
differentAssignment()43   public void differentAssignment() {
44     DSimple ds = new DSimple();
45     new JCommander(ds).parse("-D", "a=b", "-A", "c@d");
46     Assert.assertEquals(ds.params, Maps.newHashMap("a", "b"));
47     Assert.assertEquals(ds.params2, Maps.newHashMap("c", "d"));
48   }
49 
50   @Test(enabled = false)
main(String[] args)51   public static void main(String[] args) {
52     DynamicParameterTest dpt = new DynamicParameterTest();
53     dpt.simpleWithSpaces();
54 //    dpt.nonMapShouldThrow();
55 //    dpt.wrongSeparatorShouldThrow();
56 //    dpt.differentAssignment();
57 //    dpt.arity0();
58 //    dpt.usage();
59   }
60 }
61