1 package com.beust.jcommander;
2 
3 import org.testng.Assert;
4 import org.testng.annotations.Test;
5 
6 import java.util.Arrays;
7 import java.util.LinkedList;
8 import java.util.List;
9 
10 public class VariableArityTest {
11 
12   public static class ModelGenerationConfig {
13 
14     @Parameter(names = { "-m", "--matrixData" }, variableArity = true,
15         description = "File containing a list of instances and their runtimes on various configurations", required = false)
16     public List<String> modelMatrixFile = new LinkedList<String>();
17 
18     @Parameter(names = { "-f", "--featureData" }, variableArity = true,
19         description = "File containing a list of instances and their corresponding features", required = true)
20     public List<String> featureFile = new LinkedList<String>();
21 
22     @Parameter(names = { "-c", "--configData" }, variableArity = true,
23         description = "File containing a list of configuration parameter values")
24     public List<String> configFile = new LinkedList<String>();
25 
26     @Parameter(names = { "-o", "--outputFile" },
27         description = "File to output the resulting data to. Defaults to ./matrix-generation.zip", required = false)
28     public String outputFile = "matrix-generation.zip";
29 
30     @Parameter(names = { "--seed" }, description = "Seed used for PRNG [0 means don't use a Seed]")
31     public long seed = 0;
32 
print()33     public void print() {
34       System.out.println("modelMatrixFile: " + modelMatrixFile);
35       System.out.println("featureData: " + featureFile);
36       System.out.println("configFile: " + configFile);
37       System.out.println("output:  " + outputFile);
38       System.out.println("seed: " + seed);
39 
40     }
41   }
42 
43   @Test
verifyVariableArity()44   public void verifyVariableArity() {
45     String input = "-m foo --seed 1024 -c foo -o foo -f foo ";
46 
47     String[] split = input.split("\\s+");
48 
49     ModelGenerationConfig config = new ModelGenerationConfig();
50     JCommander com = new JCommander(config);
51     com.setProgramName("modelgen");
52 
53     com.parse(split);
54 
55 //    config.print();
56     Assert.assertNotEquals(config.seed, 0);
57     Assert.assertEquals(config.modelMatrixFile, Arrays.asList(new String[] { "foo" }));
58     Assert.assertEquals(config.featureFile, Arrays.asList(new String[] { "foo" }));
59     Assert.assertEquals(config.seed, 1024);
60     Assert.assertEquals(config.outputFile, "foo");
61   }
62 
main(String[] args)63   public static void main(String[] args) {
64     new VariableArityTest().verifyVariableArity();
65   }
66 }