1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package org.kohsuke.args4j;
import junit.framework.TestCase;
public class FieldParserTest extends TestCase {
private void parse(Object bean, String... args) throws CmdLineException, ClassNotFoundException {
CmdLineParser p = new CmdLineParser(new Object());
new FieldParser().parse(p, bean);
p.parseArgument(args);
}
public void testNoArgs() throws CmdLineException, ClassNotFoundException {
Bean bean = new Bean();
parse(bean);
assertEquals("default", bean.text);
assertEquals(-1, bean.number);
}
public void testFields() throws CmdLineException, ClassNotFoundException {
Bean bean = new Bean();
parse(bean, "-text", "newText", "-number", "42");
assertEquals("newText", bean.text);
assertEquals(42, bean.number);
}
public void testInheritedFields() throws CmdLineException, ClassNotFoundException {
InheritedBean bean = new InheritedBean();
parse(bean, "-text", "newText", "-number", "42", "-text2", "newText");
assertEquals("newText", bean.text2);
assertEquals("newText", bean.text);
assertEquals(42, bean.number);
}
}
|