Added tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
b24b72f3e2
commit
5e5cc2a1cd
@ -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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user