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

Last change on this file since 668 was 668, checked in by sherbold, 12 years ago
  • fixed tests that needed to be changed due to Command-API change
  • Property svn:mime-type set to text/plain
File size: 3.1 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_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 = "Usage: 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 testGetInstance_1()
92                throws Exception {
93                CommandExecuter result = CommandExecuter.getInstance();
94
95                assertNotNull(result);
96        }
97       
98        @BeforeClass
99        public static void setupBeforeClass() {
100                Console.reset();
101        }
102
103        public static void main(String[] args) {
104                new org.junit.runner.JUnitCore().run(CommandExecuterTest.class);
105        }
106}
Note: See TracBrowser for help on using the repository browser.