Let's test the JCommander on a self instance.

This commit is contained in:
graywolf336 2013-12-18 14:04:04 -06:00
parent 84dbfc3063
commit 6158aae5b5
2 changed files with 20 additions and 27 deletions

View File

@ -1,21 +1,34 @@
package test.java.com.graywolf336.jail;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import com.beust.jcommander.JCommander;
import test.java.com.graywolf336.jail.util.JCommanderExample;
import com.beust.jcommander.Parameter;
public class TestJCommander {
@Parameter
public List<String> parameters = new ArrayList<String>();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
public Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
@Parameter(names = "-debug", description = "Debug mode")
public boolean debug = false;
@Test
public void testIt() {
JCommanderExample jce = new JCommanderExample();
public void testJCommander() {
String[] args = { "-log", "2", "-groups", "unit" };
new JCommander(jce, args);
new JCommander(this, args);
Assert.assertEquals(jce.verbose.intValue(), 2);
Assert.assertEquals(jce.groups.toLowerCase(), "unit");
Assert.assertEquals(this.verbose.intValue(), 2);
Assert.assertEquals(this.groups.toLowerCase(), "unit");
}
}

View File

@ -1,20 +0,0 @@
package test.java.com.graywolf336.jail.util;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.Parameter;
public class JCommanderExample {
@Parameter
public List<String> parameters = new ArrayList<String>();
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
public Integer verbose = 1;
@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
@Parameter(names = "-debug", description = "Debug mode")
public boolean debug = false;
}