/
TestMultiParser.java
62 lines (45 loc) · 1.81 KB
/
TestMultiParser.java
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
51
52
53
54
55
56
57
58
59
60
61
62
package dk.eSoftware.commandLineParser;
import org.junit.Test;
import java.util.HashMap;
import static org.junit.Assert.*;
public class TestMultiParser {
@Test
public void testMultiParser() {
HashMap<String, CommandLineParser.ConfigBuilder<? extends Configuration>> map = new HashMap<>();
map.put("A", new TestConfigBuilder("A"));
map.put("B", new TestConfigBuilder("B"));
final MultiParser<Configuration> multiParser = new MultiParser<>(map);
try {
final CommandLineParser.ConfigBuilder<?> parserA = multiParser.getConfigBuilder("A");
assertEquals("Wrong parser returned", "A", parserA.help());
final CommandLineParser.ConfigBuilder<?> parserB = multiParser.getConfigBuilder("B");
assertEquals("Wrong parser returned", "B", parserB.help());
assertEquals("Wrong help string", "Help information compiled by CommandLineParser:\nA\nB\n", multiParser.help());
} catch (NoSuchBuilderException e) {
fail("An exception was thrown");
}
try {
final CommandLineParser.ConfigBuilder<?> c = multiParser.getConfigBuilder("C");
assertNull("Should not exist", c);
fail("Should have thrown exception");
} catch (NoSuchBuilderException expected) {
}
}
private static class TestConfigBuilder implements CommandLineParser.ConfigBuilder<Configuration> {
private final String id;
public TestConfigBuilder(String id) {
this.id = id;
}
@Override
public void applyCommand(CommandLineParser.Command command) {
}
@Override
public Configuration build() {
return null;
}
@Override
public String help() {
return id;
}
}
}