source: trunk/java-utils-test/src/test/java/de/ugoe/cs/util/console/defaultcommands/CMDexitTest.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: 2.1 KB
Line 
1package de.ugoe.cs.util.console.defaultcommands;
2
3import java.security.Permission;
4import java.util.ArrayList;
5import java.util.List;
6import org.junit.*;
7
8import de.ugoe.cs.util.console.Console;
9import de.ugoe.cs.util.console.mock.MockOutputListener;
10import static org.junit.Assert.*;
11
12/**
13 * The class <code>CMDexitTest</code> contains tests for the class
14 * <code>{@link CMDexit}</code>.
15 *
16 * @author Steffen Herbold
17 * @version 1.0
18 */
19public class CMDexitTest {
20
21        final static String ENDLINE = System.getProperty("line.separator");
22
23        private static class ExitException extends SecurityException {
24                private static final long serialVersionUID = 1L;
25        }
26
27        private static class NoExitSecurityManager extends SecurityManager {
28                @Override
29                public void checkPermission(Permission perm) {
30                        // allow anything.
31                }
32
33                @Override
34                public void checkPermission(Permission perm, Object context) {
35                        // allow anything.
36                }
37
38                @Override
39                public void checkExit(int status) {
40                        super.checkExit(status);
41                        throw new ExitException();
42                }
43        }
44
45        @Test
46        public void testHelp_1() throws Exception {
47                CMDexit fixture = new CMDexit();
48                MockOutputListener mockListener = new MockOutputListener();
49                Console.getInstance().registerOutputListener(mockListener);
50                String expected = "exit";
51
52                assertEquals(expected, fixture.help());
53        }
54
55        @Test(expected = ExitException.class)
56        public void testRun_1() throws Exception {
57                CMDexit fixture = new CMDexit();
58                List<Object> parameters = new ArrayList<Object>();
59
60                fixture.run(parameters);
61        }
62
63        @Test(expected = ExitException.class)
64        public void testRun_2() throws Exception {
65                CMDexit fixture = new CMDexit();
66                List<Object> parameters = new ArrayList<Object>();
67                parameters.add("test");
68
69                fixture.run(parameters);
70        }
71
72        @Before
73        public void setUp() throws Exception {
74                System.setSecurityManager(new NoExitSecurityManager());
75        }
76
77        @After
78        public void tearDown() throws Exception {
79                System.setSecurityManager(null);
80        }
81
82        public static void main(String[] args) {
83                new org.junit.runner.JUnitCore().run(CMDexitTest.class);
84        }
85}
Note: See TracBrowser for help on using the repository browser.