source: trunk/JavaHelperLibTest/src/de/ugoe/cs/util/console/CommandExecuterTest.java @ 320

Last change on this file since 320 was 319, checked in by sherbold, 14 years ago
  • Property svn:mime-type set to text/plain
File size: 3.6 KB
Line 
1package de.ugoe.cs.util.console;
2
3import org.junit.*;
4
5import de.ugoe.cs.util.console.mock.MockOutputListener;
6import static org.junit.Assert.*;
7
8/**
9 * The class <code>CommandExecuterTest</code> contains tests for the class
10 * <code>{@link CommandExecuter}</code>.
11 *
12 * @author Steffen Herbold
13 * @version 1.0
14 */
15public class CommandExecuterTest {
16
17        @Test(expected=java.security.InvalidParameterException.class)
18        public void testAddCommandPackage_1()
19                throws Exception {
20                CommandExecuter fixture = CommandExecuter.getInstance();
21
22                fixture.addCommandPackage("");
23        }
24
25        @Test(expected=java.security.InvalidParameterException.class)
26        public void testAddCommandPackage_fixtureInstance_2()
27                throws Exception {
28                CommandExecuter fixture = CommandExecuter.getInstance();
29               
30                fixture.addCommandPackage(null);
31        }
32
33        @Test
34        public void testExec_1()
35                throws Exception {
36                CommandExecuter fixture = CommandExecuter.getInstance();
37                MockOutputListener mockListener = new MockOutputListener();
38                Console.getInstance().registerOutputListener(mockListener);
39                fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
40                String command = "mockCommand";
41                String expected = "mock command: run" + System.getProperty("line.separator");
42
43                fixture.exec(command);
44
45                assertEquals(expected, mockListener.getLastOutput());
46        }
47       
48        @Test
49        public void testExec_2()
50                throws Exception {
51                CommandExecuter fixture = CommandExecuter.getInstance();
52                MockOutputListener mockListener = new MockOutputListener();
53                Console.getInstance().registerOutputListener(mockListener);
54                fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
55                String command = "mockCommand param1";
56                String expected = "mock command: help" + System.getProperty("line.separator");
57
58                fixture.exec(command);
59
60                assertEquals(expected, mockListener.getLastOutput());
61        }
62       
63        @Test(expected = java.lang.RuntimeException.class)
64        public void testExec_3()
65                throws Exception {
66                CommandExecuter fixture = CommandExecuter.getInstance();
67                MockOutputListener mockListener = new MockOutputListener();
68                Console.getInstance().registerOutputListener(mockListener);
69                fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
70                String command = "mockCommand param1 param2";
71
72                fixture.exec(command);
73        }
74       
75        @Test
76        public void testExec_4()
77                throws Exception {
78                CommandExecuter fixture = CommandExecuter.getInstance();
79                MockOutputListener mockListener = new MockOutputListener();
80                Console.getInstance().registerOutputListener(mockListener);
81                fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
82                String command = "mockCommandddd";
83                String expected = "Unknown command" + System.getProperty("line.separator");
84               
85                fixture.exec(command);
86               
87                assertEquals(expected, mockListener.getLastOutput());
88        }
89
90        @Test
91        public void testExec_5()
92                throws Exception {
93                CommandExecuter fixture = CommandExecuter.getInstance();
94                MockOutputListener mockListener = new MockOutputListener();
95                Console.getInstance().registerOutputListener(mockListener);
96                fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands");
97                String command = "mockCommanD";
98                String expected = "Did you mean mockCommand?" + System.getProperty("line.separator");
99               
100                fixture.exec(command);
101               
102                assertEquals(expected, mockListener.getSecondLastOutput());
103        }
104
105        @Test
106        public void testGetInstance_1()
107                throws Exception {
108                CommandExecuter result = CommandExecuter.getInstance();
109
110                assertNotNull(result);
111        }
112
113        public static void main(String[] args) {
114                new org.junit.runner.JUnitCore().run(CommandExecuterTest.class);
115        }
116}
Note: See TracBrowser for help on using the repository browser.