source: trunk/java-utils-test/src/test/java/de/ugoe/cs/util/console/CommandParserTest.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 8.5 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.util.console;
16
17import java.util.ArrayList;
18import java.util.List;
19import org.junit.*;
20import static org.junit.Assert.*;
21
22/**
23 * The class <code>CommandParserTest</code> contains tests for the class
24 * <code>{@link CommandParser}</code>.
25 *
26 * @author Steffen Herbold
27 * @version 1.0
28 */
29public class CommandParserTest {
30
31        @Test
32        public void testCommandParser_1() throws Exception {
33
34                CommandParser result = new CommandParser();
35
36                // add additional test code here
37                assertNotNull(result);
38                assertEquals("", result.getCommandName());
39                assertTrue(result.getParameters().isEmpty());
40        }
41
42        @Test
43        public void testGetParameters_1() throws Exception {
44                CommandParser fixture = new CommandParser();
45
46                List<Object> result = fixture.getParameters();
47
48                // add additional test code here
49                assertNotNull(result);
50                assertEquals(0, result.size());
51        }
52
53        @Test
54        public void testParse_1() throws Exception {
55                CommandParser commandParser = new CommandParser();
56                String command = "test";
57                commandParser.parse(command);
58
59                assertEquals("test", commandParser.getCommandName());
60                assertTrue(commandParser.getParameters().isEmpty());
61        }
62
63        @Test
64        public void testParse_2() throws Exception {
65                CommandParser commandParser = new CommandParser();
66                String command = "test param1";
67                List<Object> expectedParameters = new ArrayList<Object>();
68                expectedParameters.add("param1");
69
70                commandParser.parse(command);
71
72                assertEquals("test", commandParser.getCommandName());
73                assertArrayEquals(expectedParameters.toArray(), commandParser
74                                .getParameters().toArray());
75        }
76
77        @Test
78        public void testParse_3() throws Exception {
79                CommandParser commandParser = new CommandParser();
80                String command = "test param1 param2";
81                List<Object> expectedParameters = new ArrayList<Object>();
82                expectedParameters.add("param1");
83                expectedParameters.add("param2");
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_4() throws Exception {
94                CommandParser commandParser = new CommandParser();
95                String command = "test [array1]";
96                List<Object> expectedParameters = new ArrayList<Object>();
97                expectedParameters.add(new String[] { "array1" });
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_5() throws Exception {
108                CommandParser commandParser = new CommandParser();
109                String command = "test [array1 array2]";
110                List<Object> expectedParameters = new ArrayList<Object>();
111                expectedParameters.add(new String[] { "array1", "array2" });
112
113                commandParser.parse(command);
114
115                assertEquals("test", commandParser.getCommandName());
116                assertArrayEquals(expectedParameters.toArray(), commandParser
117                                .getParameters().toArray());
118        }
119
120        @Test
121        public void testParse_6() throws Exception {
122                CommandParser commandParser = new CommandParser();
123                String command = "test [array1] param1";
124                List<Object> expectedParameters = new ArrayList<Object>();
125                expectedParameters.add(new String[] { "array1" });
126                expectedParameters.add("param1");
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_7() throws Exception {
137                CommandParser commandParser = new CommandParser();
138                String command = "test 'param 1'";
139                List<Object> expectedParameters = new ArrayList<Object>();
140                expectedParameters.add("param 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_8() throws Exception {
151                CommandParser commandParser = new CommandParser();
152                String command = "test ['array 1']";
153                List<Object> expectedParameters = new ArrayList<Object>();
154                expectedParameters.add(new String[] { "array 1" });
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_9() throws Exception {
165                CommandParser commandParser = new CommandParser();
166                String command = "test ['array 1' array2]";
167                List<Object> expectedParameters = new ArrayList<Object>();
168                expectedParameters.add(new String[] { "array 1", "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_10() throws Exception {
179                CommandParser commandParser = new CommandParser();
180                String command = "test [array1  array2]";
181                List<Object> expectedParameters = new ArrayList<Object>();
182                expectedParameters.add(new String[] { "array1", "array2" });
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_11() throws Exception {
193                CommandParser commandParser = new CommandParser();
194                String command = "test 'param 1";
195                List<Object> expectedParameters = new ArrayList<Object>();
196                expectedParameters.add("param 1");
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_12() throws Exception {
207                CommandParser commandParser = new CommandParser();
208                String command = "test 'param1 [array1]";
209                List<Object> expectedParameters = new ArrayList<Object>();
210                expectedParameters.add("param1 [array1]");
211
212                commandParser.parse(command);
213
214                assertEquals("test", commandParser.getCommandName());
215                assertArrayEquals(expectedParameters.toArray(), commandParser
216                                .getParameters().toArray());
217        }
218
219        @Test
220        public void testParse_13() throws Exception {
221                CommandParser commandParser = new CommandParser();
222                String command = "test param1' [array1]";
223                List<Object> expectedParameters = new ArrayList<Object>();
224                expectedParameters.add("param1'");
225                expectedParameters.add(new String[] { "array1" });
226
227                commandParser.parse(command);
228
229                assertEquals("test", commandParser.getCommandName());
230                assertArrayEquals(expectedParameters.toArray(), commandParser
231                                .getParameters().toArray());
232        }
233
234        @Test
235        public void testParse_14() throws Exception {
236                CommandParser commandParser = new CommandParser();
237                String command = "";
238                commandParser.parse(command);
239                assertEquals("", commandParser.getCommandName());
240                assertTrue(commandParser.getParameters().isEmpty());
241        }
242
243        @Test
244        public void testParse_15() throws Exception {
245                CommandParser commandParser = new CommandParser();
246                String command = null;
247                commandParser.parse(command);
248                assertEquals("", commandParser.getCommandName());
249                assertTrue(commandParser.getParameters().isEmpty());
250        }
251
252        @Test
253        public void testParse_16() throws Exception {
254                CommandParser commandParser = new CommandParser();
255                String command = "test param1  param2";
256                List<Object> expectedParameters = new ArrayList<Object>();
257                expectedParameters.add("param1");
258                expectedParameters.add("param2");
259
260                commandParser.parse(command);
261                assertEquals("test", commandParser.getCommandName());
262                assertArrayEquals(expectedParameters.toArray(), commandParser
263                                .getParameters().toArray());
264        }
265
266        public static void main(String[] args) {
267                new org.junit.runner.JUnitCore().run(CommandParserTest.class);
268        }
269}
Note: See TracBrowser for help on using the repository browser.