1 | package de.ugoe.cs.util.console;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 | import org.junit.*;
|
---|
6 | import static org.junit.Assert.*;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * The class <code>CommandParserTest</code> contains tests for the class
|
---|
10 | * <code>{@link CommandParser}</code>.
|
---|
11 | *
|
---|
12 | * @author Steffen Herbold
|
---|
13 | * @version 1.0
|
---|
14 | */
|
---|
15 | public class CommandParserTest {
|
---|
16 |
|
---|
17 | @Test
|
---|
18 | public void testCommandParser_1() throws Exception {
|
---|
19 |
|
---|
20 | CommandParser result = new CommandParser();
|
---|
21 |
|
---|
22 | // add additional test code here
|
---|
23 | assertNotNull(result);
|
---|
24 | assertEquals("", result.getCommandName());
|
---|
25 | assertTrue(result.getParameters().isEmpty());
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Test
|
---|
29 | public void testGetParameters_1() throws Exception {
|
---|
30 | CommandParser fixture = new CommandParser();
|
---|
31 |
|
---|
32 | List<Object> result = fixture.getParameters();
|
---|
33 |
|
---|
34 | // add additional test code here
|
---|
35 | assertNotNull(result);
|
---|
36 | assertEquals(0, result.size());
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test
|
---|
40 | public void testParse_1() throws Exception {
|
---|
41 | CommandParser commandParser = new CommandParser();
|
---|
42 | String command = "test";
|
---|
43 | commandParser.parse(command);
|
---|
44 |
|
---|
45 | assertEquals("test", commandParser.getCommandName());
|
---|
46 | assertTrue(commandParser.getParameters().isEmpty());
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Test
|
---|
50 | public void testParse_2() throws Exception {
|
---|
51 | CommandParser commandParser = new CommandParser();
|
---|
52 | String command = "test param1";
|
---|
53 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
54 | expectedParameters.add("param1");
|
---|
55 |
|
---|
56 | commandParser.parse(command);
|
---|
57 |
|
---|
58 | assertEquals("test", commandParser.getCommandName());
|
---|
59 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
60 | .getParameters().toArray());
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void testParse_3() throws Exception {
|
---|
65 | CommandParser commandParser = new CommandParser();
|
---|
66 | String command = "test param1 param2";
|
---|
67 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
68 | expectedParameters.add("param1");
|
---|
69 | expectedParameters.add("param2");
|
---|
70 |
|
---|
71 | commandParser.parse(command);
|
---|
72 |
|
---|
73 | assertEquals("test", commandParser.getCommandName());
|
---|
74 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
75 | .getParameters().toArray());
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Test
|
---|
79 | public void testParse_4() throws Exception {
|
---|
80 | CommandParser commandParser = new CommandParser();
|
---|
81 | String command = "test [array1]";
|
---|
82 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
83 | expectedParameters.add(new String[] { "array1" });
|
---|
84 |
|
---|
85 | commandParser.parse(command);
|
---|
86 |
|
---|
87 | assertEquals("test", commandParser.getCommandName());
|
---|
88 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
89 | .getParameters().toArray());
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Test
|
---|
93 | public void testParse_5() throws Exception {
|
---|
94 | CommandParser commandParser = new CommandParser();
|
---|
95 | String command = "test [array1 array2]";
|
---|
96 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
97 | expectedParameters.add(new String[] { "array1", "array2" });
|
---|
98 |
|
---|
99 | commandParser.parse(command);
|
---|
100 |
|
---|
101 | assertEquals("test", commandParser.getCommandName());
|
---|
102 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
103 | .getParameters().toArray());
|
---|
104 | }
|
---|
105 |
|
---|
106 | @Test
|
---|
107 | public void testParse_6() throws Exception {
|
---|
108 | CommandParser commandParser = new CommandParser();
|
---|
109 | String command = "test [array1] param1";
|
---|
110 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
111 | expectedParameters.add(new String[] { "array1" });
|
---|
112 | expectedParameters.add("param1");
|
---|
113 |
|
---|
114 | commandParser.parse(command);
|
---|
115 |
|
---|
116 | assertEquals("test", commandParser.getCommandName());
|
---|
117 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
118 | .getParameters().toArray());
|
---|
119 | }
|
---|
120 |
|
---|
121 | @Test
|
---|
122 | public void testParse_7() throws Exception {
|
---|
123 | CommandParser commandParser = new CommandParser();
|
---|
124 | String command = "test 'param 1'";
|
---|
125 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
126 | expectedParameters.add("param 1");
|
---|
127 |
|
---|
128 | commandParser.parse(command);
|
---|
129 |
|
---|
130 | assertEquals("test", commandParser.getCommandName());
|
---|
131 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
132 | .getParameters().toArray());
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Test
|
---|
136 | public void testParse_8() throws Exception {
|
---|
137 | CommandParser commandParser = new CommandParser();
|
---|
138 | String command = "test ['array 1']";
|
---|
139 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
140 | expectedParameters.add(new String[] { "array 1" });
|
---|
141 |
|
---|
142 | commandParser.parse(command);
|
---|
143 |
|
---|
144 | assertEquals("test", commandParser.getCommandName());
|
---|
145 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
146 | .getParameters().toArray());
|
---|
147 | }
|
---|
148 |
|
---|
149 | @Test
|
---|
150 | public void testParse_9() throws Exception {
|
---|
151 | CommandParser commandParser = new CommandParser();
|
---|
152 | String command = "test ['array 1' array2]";
|
---|
153 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
154 | expectedParameters.add(new String[] { "array 1", "array2" });
|
---|
155 |
|
---|
156 | commandParser.parse(command);
|
---|
157 |
|
---|
158 | assertEquals("test", commandParser.getCommandName());
|
---|
159 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
160 | .getParameters().toArray());
|
---|
161 | }
|
---|
162 |
|
---|
163 | @Test
|
---|
164 | public void testParse_10() throws Exception {
|
---|
165 | CommandParser commandParser = new CommandParser();
|
---|
166 | String command = "test [array1 array2]";
|
---|
167 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
168 | expectedParameters.add(new String[] { "array1", "array2" });
|
---|
169 |
|
---|
170 | commandParser.parse(command);
|
---|
171 |
|
---|
172 | assertEquals("test", commandParser.getCommandName());
|
---|
173 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
174 | .getParameters().toArray());
|
---|
175 | }
|
---|
176 |
|
---|
177 | @Test
|
---|
178 | public void testParse_11() throws Exception {
|
---|
179 | CommandParser commandParser = new CommandParser();
|
---|
180 | String command = "test 'param 1";
|
---|
181 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
182 | expectedParameters.add("param 1");
|
---|
183 |
|
---|
184 | commandParser.parse(command);
|
---|
185 |
|
---|
186 | assertEquals("test", commandParser.getCommandName());
|
---|
187 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
188 | .getParameters().toArray());
|
---|
189 | }
|
---|
190 |
|
---|
191 | @Test
|
---|
192 | public void testParse_12() throws Exception {
|
---|
193 | CommandParser commandParser = new CommandParser();
|
---|
194 | String command = "test 'param1 [array1]";
|
---|
195 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
196 | expectedParameters.add("param1 [array1]");
|
---|
197 |
|
---|
198 | commandParser.parse(command);
|
---|
199 |
|
---|
200 | assertEquals("test", commandParser.getCommandName());
|
---|
201 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
202 | .getParameters().toArray());
|
---|
203 | }
|
---|
204 |
|
---|
205 | @Test
|
---|
206 | public void testParse_13() throws Exception {
|
---|
207 | CommandParser commandParser = new CommandParser();
|
---|
208 | String command = "test param1' [array1]";
|
---|
209 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
210 | expectedParameters.add("param1'");
|
---|
211 | expectedParameters.add(new String[] { "array1" });
|
---|
212 |
|
---|
213 | commandParser.parse(command);
|
---|
214 |
|
---|
215 | assertEquals("test", commandParser.getCommandName());
|
---|
216 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
217 | .getParameters().toArray());
|
---|
218 | }
|
---|
219 |
|
---|
220 | @Test
|
---|
221 | public void testParse_14() throws Exception {
|
---|
222 | CommandParser commandParser = new CommandParser();
|
---|
223 | String command = "";
|
---|
224 | commandParser.parse(command);
|
---|
225 | assertEquals("", commandParser.getCommandName());
|
---|
226 | assertTrue(commandParser.getParameters().isEmpty());
|
---|
227 | }
|
---|
228 |
|
---|
229 | @Test
|
---|
230 | public void testParse_15() throws Exception {
|
---|
231 | CommandParser commandParser = new CommandParser();
|
---|
232 | String command = null;
|
---|
233 | commandParser.parse(command);
|
---|
234 | assertEquals("", commandParser.getCommandName());
|
---|
235 | assertTrue(commandParser.getParameters().isEmpty());
|
---|
236 | }
|
---|
237 |
|
---|
238 | @Test
|
---|
239 | public void testParse_16() throws Exception {
|
---|
240 | CommandParser commandParser = new CommandParser();
|
---|
241 | String command = "test param1 param2";
|
---|
242 | List<Object> expectedParameters = new ArrayList<Object>();
|
---|
243 | expectedParameters.add("param1");
|
---|
244 | expectedParameters.add("param2");
|
---|
245 |
|
---|
246 | commandParser.parse(command);
|
---|
247 | assertEquals("test", commandParser.getCommandName());
|
---|
248 | assertArrayEquals(expectedParameters.toArray(), commandParser
|
---|
249 | .getParameters().toArray());
|
---|
250 | }
|
---|
251 |
|
---|
252 | public static void main(String[] args) {
|
---|
253 | new org.junit.runner.JUnitCore().run(CommandParserTest.class);
|
---|
254 | }
|
---|
255 | } |
---|