/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lpa.command;
import junit.framework.TestCase;
import lpa.model.Edge;
import lpa.model.Edge.EdgeState;
/**
*
* @author Dimitriy Leonov
*/
public class CompoundCommandTest extends TestCase {
public CompoundCommandTest(String testName) {
super(testName);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Test of add method, of class CompoundCommand.
*/
public void testAdd() {
System.out.println("add");
CompoundCommand instance = new CompoundCommand();
try {
instance.add(null);
fail("Null-pointer exception must be raised.");
} catch (NullPointerException ex) {
assertTrue(true);
}
}
/**
* Test of execute method, of class CompoundCommand.
*/
public void testExecute() {
System.out.println("execute");
try {
Edge e = new Edge(0, 0, EdgeState.MAYBE);
Command c = new EdgeCommand(e);
CompoundCommand instance = new CompoundCommand();
instance.add(c);
instance.execute();
assertEquals("Command not executed.", c.executed, true);
assertEquals("Invalid receiver state.", e.getState(), EdgeState.YES);
} catch (Exception ex) {
fail("Exception raised.");
}
}
/**
* Test of undo method, of class CompoundCommand.
*/
public void testUndo() {
System.out.println("undo");
try {
Edge e = new Edge(0, 0, EdgeState.MAYBE);
Command c = new EdgeCommand(e);
CompoundCommand instance = new CompoundCommand();
instance.add(c);
instance.execute();
instance.undo();
assertEquals("Command not executed.", c.executed, false);
assertEquals("Invalid receiver state.", e.getState(), EdgeState.MAYBE);
} catch (Exception ex) {
fail("Exception raised.");
}
}
/**
* Test of commandCount method, of class CompoundCommand.
*/
public void testCommandCount() {
System.out.println("commandCount");
CompoundCommand instance = new CompoundCommand();
instance.add(new EdgeCommand(new Edge(0, 0, EdgeState.MAYBE)));
int expResult = 1;
int result = instance.commandCount();
assertEquals(expResult, result);
}
}