diff --git a/gclc-process/src/test/java/net/bigeon/gclc/process/ProcessAttachementTest.java b/gclc-process/src/test/java/net/bigeon/gclc/process/ProcessAttachementTest.java new file mode 100644 index 0000000..83844bb --- /dev/null +++ b/gclc-process/src/test/java/net/bigeon/gclc/process/ProcessAttachementTest.java @@ -0,0 +1,34 @@ +/** + * + */ +package net.bigeon.gclc.process; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import net.bigeon.gclc.command.SubedCommand; +import net.bigeon.gclc.exception.InvalidCommandName; + +/** + * @author Emmanuel Bigeon + * + */ +public class ProcessAttachementTest { + + /** Test method for + * {@link net.bigeon.gclc.process.ProcessAttachement#attach(net.bigeon.gclc.command.ICommandProvider)}. + * + * @throws InvalidCommandName if the command has already some subcommand that is + * incompatible */ + @Test + public void testAttach() throws InvalidCommandName { + final TaskPool pool = new TaskPool(); + final ProcessAttachement attachement = new ProcessAttachement(pool); + final SubedCommand testPoint = new SubedCommand("test"); + attachement.attach(testPoint); + assertNotNull("Commands should be added", testPoint.get("kill")); + assertNotNull("Commands should be added", testPoint.get("list")); + } + +} diff --git a/gclc-process/src/test/java/net/bigeon/gclc/process/ScreenAttachementTest.java b/gclc-process/src/test/java/net/bigeon/gclc/process/ScreenAttachementTest.java new file mode 100644 index 0000000..86b3699 --- /dev/null +++ b/gclc-process/src/test/java/net/bigeon/gclc/process/ScreenAttachementTest.java @@ -0,0 +1,33 @@ +/** + * + */ +package net.bigeon.gclc.process; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import net.bigeon.gclc.command.SubedCommand; +import net.bigeon.gclc.exception.InvalidCommandName; + +/** @author Emmanuel Bigeon */ +public class ScreenAttachementTest { + + /** Test method for + * {@link net.bigeon.gclc.process.ScreenAttachement#attach(net.bigeon.gclc.command.ICommandProvider)}. + * + * @throws InvalidCommandName if an error occured in attachement */ + @Test + public void testAttach() throws InvalidCommandName { + final TaskPool pool = new TaskPool(); + final ScreenAttachement attachement = new ScreenAttachement(pool, 15); + final SubedCommand testPoint = new SubedCommand("test"); + attachement.attach(testPoint); + assertNotNull("Commands should be added", testPoint.get("terminate")); + assertNotNull("Commands should be added", testPoint.get("list")); + assertNotNull("Commands should be added", testPoint.get("clear")); + assertNotNull("Commands should be added", testPoint.get("fg")); + assertNotNull("Commands should be added", testPoint.get("fork")); + } + +} diff --git a/gclc-process/src/test/java/net/bigeon/gclc/process/TaskSpawnerTest.java b/gclc-process/src/test/java/net/bigeon/gclc/process/TaskSpawnerTest.java new file mode 100644 index 0000000..d51d3d6 --- /dev/null +++ b/gclc-process/src/test/java/net/bigeon/gclc/process/TaskSpawnerTest.java @@ -0,0 +1,80 @@ +/** + * + */ +package net.bigeon.gclc.process; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.junit.Test; + +import net.bigeon.gclc.exception.CommandRunException; +import net.bigeon.gclc.manager.ConsoleInput; +import net.bigeon.gclc.manager.ConsoleOutput; + +/** @author Emmanuel Bigeon */ +public class TaskSpawnerTest { + + /** Test method for + * {@link net.bigeon.gclc.process.TaskSpawner#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}. + * + * @throws CommandRunException if an error occurred */ + @Test + public void testExecute() throws CommandRunException { + final Task task = new Task() { + @Override + public void run() { + // + } + @Override + public void setRunning(final boolean running) { + // + } + @Override + public void rmInterruptionListener(final InterruptionListener listener) { + // + } + @Override + public boolean isRunning() { + return false; + } + @Override + public String getName() { + return "abc"; + } + @Override + public void addInterruptionListener(final InterruptionListener listener) { + // + } + }; + final TaskPool pool = new TaskPool(); + assertTrue("Pool not empty", pool.getPIDs().isEmpty()); + final ExecutorService service = Executors.newSingleThreadExecutor(); + final TaskSpawner spawner = new TaskSpawner("name", pool, service) { + + @Override + public String tip() { + return "tip"; + } + + @Override + protected String usageDetail() { + return "no details"; + } + + @Override + protected Task createTask(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { + return task; + } + }; + spawner.execute(null, null); + assertEquals("Added the task", 1, pool.getPIDs().size()); + final Integer id = pool.getPIDs().iterator().next(); + assertEquals("Added task is not the one", task, pool.get(id)); + } + +}