blob: b8000cab2488e88ad6a78f6b44f8103a5154659f (
plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package com.beust.jcommander;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.PrintWriter;
import java.io.StringWriter;
import static org.testng.Assert.assertEquals;
class Main {
static PrintWriter out;
@Parameter(names={"--length", "-l"})
int length;
@Parameter(names={"--pattern", "-p"})
int pattern;
public static void main(String ... args) {
Main main = new Main();
new JCommander(main, args);
main.run();
}
public void run() {
out.printf("%d %d", length, pattern);
}
}
public class SimpleExample {
StringWriter out;
@BeforeMethod
public void setupMain(){
out=new StringWriter();
Main.out=new PrintWriter(out);
}
@Test
public void testLongArgs() {
Main.main("--length", "512", "--pattern", "2");
assertEquals("512 2", out.toString());
}
@Test
public void testShortArgs() {
Main.main("-l", "256", "-p", "171");
assertEquals("256 171", out.toString());
}
}
|