1 | package de.ugoe.cs.util.console.defaultcommands;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 | import org.junit.*;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.util.console.Console;
|
---|
8 | import de.ugoe.cs.util.console.mock.MockCommandListener;
|
---|
9 | import de.ugoe.cs.util.console.mock.MockOutputListener;
|
---|
10 | import de.ugoe.cs.util.console.mock.MockTraceListener;
|
---|
11 | import static org.junit.Assert.*;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * The class <code>CMDexecTest</code> contains tests for the class
|
---|
15 | * <code>{@link CMDexec}</code>.
|
---|
16 | *
|
---|
17 | * @author Steffen Herbold
|
---|
18 | * @version 1.0
|
---|
19 | */
|
---|
20 | public class CMDexecTest {
|
---|
21 |
|
---|
22 | final static String ENDLINE = System.getProperty("line.separator");
|
---|
23 |
|
---|
24 | @Test
|
---|
25 | public void testHelp_1() throws Exception {
|
---|
26 | CMDexec fixture = new CMDexec();
|
---|
27 | MockOutputListener mockListener = new MockOutputListener();
|
---|
28 | Console.getInstance().registerOutputListener(mockListener);
|
---|
29 | String expected = "Usage: exec <filename>" + ENDLINE;
|
---|
30 |
|
---|
31 | fixture.help();
|
---|
32 |
|
---|
33 | assertEquals(expected, mockListener.getLastOutput());
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Test
|
---|
37 | public void testRun_1() throws Exception {
|
---|
38 | CMDexec fixture = new CMDexec();
|
---|
39 | MockCommandListener mockCommandListener = new MockCommandListener();
|
---|
40 | MockTraceListener mockTraceListener = new MockTraceListener();
|
---|
41 | Console.getInstance().registerCommandListener(mockCommandListener);
|
---|
42 | Console.getInstance().registerTraceListener(mockTraceListener);
|
---|
43 | List<Object> parameters = new ArrayList<Object>();
|
---|
44 | parameters
|
---|
45 | .add("testdata/de.ugoe.cs.util.console.defaultcommands.CMDexecTest/script1");
|
---|
46 | String expected = "mockCommand";
|
---|
47 |
|
---|
48 | fixture.run(parameters);
|
---|
49 |
|
---|
50 | assertEquals(expected, mockCommandListener.getLastCommand());
|
---|
51 | assertEquals(expected + ENDLINE, mockTraceListener.getLastTrace());
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Test
|
---|
55 | public void testRun_2() throws Exception {
|
---|
56 | CMDexec fixture = new CMDexec();
|
---|
57 | MockCommandListener mockCommandListener = new MockCommandListener();
|
---|
58 | MockTraceListener mockTraceListener = new MockTraceListener();
|
---|
59 | Console.getInstance().registerCommandListener(mockCommandListener);
|
---|
60 | Console.getInstance().registerTraceListener(mockTraceListener);
|
---|
61 | List<Object> parameters = new ArrayList<Object>();
|
---|
62 | parameters
|
---|
63 | .add("testdata/de.ugoe.cs.util.console.defaultcommands.CMDexecTest/script2");
|
---|
64 | String expected = "mockCommand param1";
|
---|
65 |
|
---|
66 | fixture.run(parameters);
|
---|
67 |
|
---|
68 | assertEquals(expected, mockCommandListener.getLastCommand());
|
---|
69 | assertEquals(expected + ENDLINE, mockTraceListener.getLastTrace());
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
73 | public void testRun_3() throws Exception {
|
---|
74 | CMDexec fixture = new CMDexec();
|
---|
75 | MockCommandListener mockCommandListener = new MockCommandListener();
|
---|
76 | MockTraceListener mockTraceListener = new MockTraceListener();
|
---|
77 | Console.getInstance().registerCommandListener(mockCommandListener);
|
---|
78 | Console.getInstance().registerTraceListener(mockTraceListener);
|
---|
79 | List<Object> parameters = new ArrayList<Object>();
|
---|
80 |
|
---|
81 | fixture.run(parameters);
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test
|
---|
85 | public void testRun_4() throws Exception {
|
---|
86 | CMDexec fixture = new CMDexec();
|
---|
87 | MockCommandListener mockCommandListener = new MockCommandListener();
|
---|
88 | MockTraceListener mockTraceListener = new MockTraceListener();
|
---|
89 | Console.getInstance().registerCommandListener(mockCommandListener);
|
---|
90 | Console.getInstance().registerTraceListener(mockTraceListener);
|
---|
91 | List<Object> parameters = new ArrayList<Object>();
|
---|
92 | parameters
|
---|
93 | .add("testdata/de.ugoe.cs.util.console.defaultcommands.CMDexecTest/script2");
|
---|
94 | parameters.add(Integer.parseInt("1"));
|
---|
95 | String expected = "mockCommand param1";
|
---|
96 |
|
---|
97 | fixture.run(parameters);
|
---|
98 |
|
---|
99 | assertEquals(expected, mockCommandListener.getLastCommand());
|
---|
100 | assertEquals(expected + ENDLINE, mockTraceListener.getLastTrace());
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
104 | public void testRun_5() throws Exception {
|
---|
105 | CMDexec fixture = new CMDexec();
|
---|
106 | List<Object> parameters = new ArrayList<Object>();
|
---|
107 | parameters.add(Integer.parseInt("1"));
|
---|
108 |
|
---|
109 | fixture.run(parameters);
|
---|
110 | }
|
---|
111 |
|
---|
112 | public static void main(String[] args) {
|
---|
113 | new org.junit.runner.JUnitCore().run(CMDexecTest.class);
|
---|
114 | }
|
---|
115 | } |
---|