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 |
|
---|
15 | package de.ugoe.cs.util.console;
|
---|
16 |
|
---|
17 | import org.junit.*;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.util.console.mock.MockOutputListener;
|
---|
20 | import static org.junit.Assert.*;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The class <code>CommandExecuterTest</code> contains tests for the class
|
---|
24 | * <code>{@link CommandExecuter}</code>.
|
---|
25 | *
|
---|
26 | * @author Steffen Herbold
|
---|
27 | * @version 1.0
|
---|
28 | */
|
---|
29 | public class CommandExecuterTest {
|
---|
30 |
|
---|
31 | @Test(expected=java.lang.IllegalArgumentException.class)
|
---|
32 | public void testAddCommandPackage_1()
|
---|
33 | throws Exception {
|
---|
34 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
35 |
|
---|
36 | fixture.addCommandPackage("");
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test(expected=java.lang.IllegalArgumentException.class)
|
---|
40 | public void testAddCommandPackage_2()
|
---|
41 | throws Exception {
|
---|
42 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
43 |
|
---|
44 | fixture.addCommandPackage(null);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void testExec_1()
|
---|
49 | throws Exception {
|
---|
50 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
51 | MockOutputListener mockListener = new MockOutputListener();
|
---|
52 | Console.getInstance().registerOutputListener(mockListener);
|
---|
53 | fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
|
---|
54 | String command = "mockCommand";
|
---|
55 | String expected = "mock command: run" + System.getProperty("line.separator");
|
---|
56 |
|
---|
57 | fixture.exec(command);
|
---|
58 |
|
---|
59 | assertEquals(expected, mockListener.getLastOutput());
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void testExec_2()
|
---|
64 | throws Exception {
|
---|
65 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
66 | MockOutputListener mockListener = new MockOutputListener();
|
---|
67 | Console.getInstance().registerOutputListener(mockListener);
|
---|
68 | fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
|
---|
69 | String command = "mockCommand param1";
|
---|
70 | String expected = "Usage: mock command: help" + System.getProperty("line.separator");
|
---|
71 |
|
---|
72 | fixture.exec(command);
|
---|
73 |
|
---|
74 | assertEquals(expected, mockListener.getLastOutput());
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Test(expected = java.lang.RuntimeException.class)
|
---|
78 | public void testExec_3()
|
---|
79 | throws Exception {
|
---|
80 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
81 | MockOutputListener mockListener = new MockOutputListener();
|
---|
82 | Console.getInstance().registerOutputListener(mockListener);
|
---|
83 | fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
|
---|
84 | String command = "mockCommand param1 param2";
|
---|
85 |
|
---|
86 | fixture.exec(command);
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Test
|
---|
90 | public void testExec_4()
|
---|
91 | throws Exception {
|
---|
92 | CommandExecuter fixture = CommandExecuter.getInstance();
|
---|
93 | MockOutputListener mockListener = new MockOutputListener();
|
---|
94 | Console.getInstance().registerOutputListener(mockListener);
|
---|
95 | fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
|
---|
96 | String command = "mockCommandddd";
|
---|
97 | String expected = "Unknown command" + System.getProperty("line.separator");
|
---|
98 |
|
---|
99 | fixture.exec(command);
|
---|
100 |
|
---|
101 | assertEquals(expected, mockListener.getLastOutput());
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Test
|
---|
105 | public void testGetInstance_1()
|
---|
106 | throws Exception {
|
---|
107 | CommandExecuter result = CommandExecuter.getInstance();
|
---|
108 |
|
---|
109 | assertNotNull(result);
|
---|
110 | }
|
---|
111 |
|
---|
112 | @BeforeClass
|
---|
113 | public static void setupBeforeClass() {
|
---|
114 | Console.reset();
|
---|
115 | }
|
---|
116 |
|
---|
117 | public static void main(String[] args) {
|
---|
118 | new org.junit.runner.JUnitCore().run(CommandExecuterTest.class);
|
---|
119 | }
|
---|
120 | } |
---|