Initial commit
This commit is contained in:
43
src/test/java/test/argparser/ArgParserTest.java
Normal file
43
src/test/java/test/argparser/ArgParserTest.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package test.argparser;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.locusworks.argparser.ArgParser;
|
||||
import net.locusworks.argparser.annotations.Parameter;
|
||||
import net.locusworks.argparser.converters.IntegerConverter;
|
||||
|
||||
public class ArgParserTest {
|
||||
|
||||
public static class Args {
|
||||
@Parameter(names="position2", positional=true, order=2)
|
||||
public String position2;
|
||||
|
||||
@Parameter(names="position1", positional=true, order=1)
|
||||
public String position1;
|
||||
|
||||
@Parameter(names="-list", variableArity=true)
|
||||
public List<String> values;
|
||||
|
||||
@Parameter(names="-count", converter=IntegerConverter.class)
|
||||
public int count;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testArgParser() {
|
||||
String[] args = new String[] {"Hello", "World", "-list", "hell", "world", "-count", "1"};
|
||||
|
||||
Args arg = ArgParser.newBuilder().withArgClass(Args.class).parse(args);
|
||||
|
||||
assertTrue(arg.position2.equals(args[0]));
|
||||
assertTrue(arg.position1.equals(args[1]));
|
||||
assertTrue(arg.values.size() == 2);
|
||||
assertTrue(arg.count == 1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user