Clover coverage report - clover
Coverage timestamp: Sat Oct 8 2005 22:54:17 EDT
file stats: LOC: 79   Methods: 8
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CommandHistoryTest.java - 88.6% 62.5% 83.7%
coverage coverage
 1   
 package abbot.editor.actions;
 2   
 
 3   
 import junit.extensions.abbot.TestHelper;
 4   
 import junit.framework.TestCase;
 5   
 
 6   
 public class CommandHistoryTest extends TestCase {
 7   
 
 8   
     private UndoableCommand undoable = new UndoableCommand() {
 9  2
         public void execute() {
 10  2
             commandRun = true;
 11   
         }
 12  2
         public void undo() {
 13  2
             commandRun = false;
 14   
         }
 15  0
         public String toString() { return "set true"; }
 16   
     };
 17   
     private Command command = new Command() {
 18  2
         public void execute() {
 19  2
             commandCount++;
 20   
         }
 21  0
         public String toString() { return "increment"; }
 22   
     };
 23   
 
 24   
     private boolean commandRun = false;
 25   
     private int commandCount = 0;
 26   
 
 27  1
     public void testUndo() throws Throwable {
 28  1
         commandRun = false;
 29  1
         CommandHistory history = new CommandHistory();
 30  1
         assertTrue("Should not be able to undo", !history.canUndo());
 31   
 
 32   
         // Command 1
 33  1
         command.execute();
 34  1
         history.add(command);
 35  1
         assertEquals("Command should have been run", 1, commandCount);
 36  1
         assertTrue("Should not be able to undo", !history.canUndo());
 37   
 
 38   
         // Command 2
 39  1
         undoable.execute();
 40  1
         history.add(undoable);
 41  1
         assertTrue("Command should have been run", commandRun);
 42  1
         assertTrue("Should be able to undo", history.canUndo());
 43   
 
 44   
         // Undo Command 2 (becomes Command 3)
 45  1
         history.undo();
 46  1
         assertTrue("Command should have been undone", !commandRun);
 47  1
         assertTrue("Should be no further undo information", !history.canUndo());
 48  1
         try {
 49  1
             history.undo();
 50  0
             fail("Expected an exception with no further undo information");
 51   
         }
 52   
         catch(NoUndoException nue) {
 53  1
             assertTrue("Should be no change", !commandRun);
 54  1
             assertTrue("Undo should now be available", history.canUndo());
 55   
         }
 56   
 
 57   
         // History should now wrap back to the end
 58   
         // Undo Command 3 (becomes Command 4)
 59  1
         history.undo();
 60  1
         assertTrue("Command should have been undone", commandRun);
 61  1
         assertTrue("Should be able to undo", history.canUndo());
 62   
         // Undo Command 2 (becomes Command 5)
 63  1
         history.undo();
 64  1
         assertTrue("Command should have been undone", !commandRun);
 65  1
         assertTrue("Should not be able to undo", !history.canUndo());
 66   
 
 67   
         // An undoable command should flush the history
 68  1
         command.execute();
 69  1
         history.add(command);
 70  1
         assertTrue("Should not be able to undo", !history.canUndo());
 71   
     }
 72   
 
 73  1
     public CommandHistoryTest(String name) { super(name); }
 74   
 
 75  0
     public static void main(String[] args) {
 76  0
         TestHelper.runTests(args, CommandHistoryTest.class);
 77   
     }
 78   
 }
 79