package de.ugoe.cs.util.console; import org.junit.*; import de.ugoe.cs.util.console.mock.MockOutputListener; import static org.junit.Assert.*; /** * The class CommandExecuterTest contains tests for the class * {@link CommandExecuter}. * * @author Steffen Herbold * @version 1.0 */ public class CommandExecuterTest { @Test(expected=java.security.InvalidParameterException.class) public void testAddCommandPackage_1() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); fixture.addCommandPackage(""); } @Test(expected=java.security.InvalidParameterException.class) public void testAddCommandPackage_2() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); fixture.addCommandPackage(null); } @Test public void testExec_1() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); MockOutputListener mockListener = new MockOutputListener(); Console.getInstance().registerOutputListener(mockListener); fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands"); String command = "mockCommand"; String expected = "mock command: run" + System.getProperty("line.separator"); fixture.exec(command); assertEquals(expected, mockListener.getLastOutput()); } @Test public void testExec_2() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); MockOutputListener mockListener = new MockOutputListener(); Console.getInstance().registerOutputListener(mockListener); fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands"); String command = "mockCommand param1"; String expected = "mock command: help" + System.getProperty("line.separator"); fixture.exec(command); assertEquals(expected, mockListener.getLastOutput()); } @Test(expected = java.lang.RuntimeException.class) public void testExec_3() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); MockOutputListener mockListener = new MockOutputListener(); Console.getInstance().registerOutputListener(mockListener); fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands"); String command = "mockCommand param1 param2"; fixture.exec(command); } @Test public void testExec_4() throws Exception { CommandExecuter fixture = CommandExecuter.getInstance(); MockOutputListener mockListener = new MockOutputListener(); Console.getInstance().registerOutputListener(mockListener); fixture.addCommandPackage("de.ugoe.cs.util.console.mock.commands"); String command = "mockCommandddd"; String expected = "Unknown command" + System.getProperty("line.separator"); fixture.exec(command); assertEquals(expected, mockListener.getLastOutput()); } @Test public void testGetInstance_1() throws Exception { CommandExecuter result = CommandExecuter.getInstance(); assertNotNull(result); } public static void main(String[] args) { new org.junit.runner.JUnitCore().run(CommandExecuterTest.class); } }