String arg2Val = null;
boolean arg3Called = false;
boolean unmatchedCalled = false;
public void testParse() throws Exception {
ArgParser parser = new ArgParser("NAME", false);
parser.addArgument("arg1", "desc1", new ArgParser.ArgumentAction() {
public void performAction(String arg) throws Exception {
arg1Val = arg;
}
});
parser.addArgument("arg2", "desc2", new ArgParser.ArgumentAction() {
public void performAction(String arg) throws Exception {
arg2Val = arg;
}
});
parser.addArgument("arg3", "desc3", new ArgParser.ArgumentAction() {
public void performAction(String arg) throws Exception {
arg3Called = true;
}
});
parser.addUnmatchedKeyArgument("xxx","yyy", new ArgParser.ArgumentAction() {
public void performAction(String arg) throws Exception {
unmatchedCalled = true;
}
});
parser.parse(new String[] {"arg1=foo", "arg2=bar"});
assertEquals("foo", arg1Val);
assertEquals("bar", arg2Val);
assertFalse(arg3Called);
parser.parse(new String[]{"arg3=foo", "arg1=bar"});
assertEquals("bar", arg1Val);
assertEquals("bar", arg2Val);
assertTrue(arg3Called);
parser.parse(new String[]{"xxx"});
assertTrue(unmatchedCalled);
}