Ticket #14526: SequenceCommandTest.java.patch

File SequenceCommandTest.java.patch, 2.5 KB (added by Tyndare, 7 years ago)

Updated version of the [PATCH] for SequenceCommandTest.java

  • core/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java

     
    9898    }
    9999
    100100    /**
     101     * Test {@link SequenceCommand#executeCommand()} rollback if case of subcommand failure.
     102     */
     103    @Test
     104    public void testExecuteRollback() {
     105        TestCommand command1 = new TestCommand(null);
     106        FailingCommand command2 = new FailingCommand();
     107        TestCommand command3 = new TestCommand(null);
     108        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3));
     109        assertFalse(command.executeCommand());
     110        assertFalse(command1.executed);
     111        // Don't check command2 executed state as it's possible but not necessary to undo failed commands
     112        assertFalse(command3.executed);
     113        command.undoCommand();
     114    }
     115
     116    /**
     117     * Test {@link SequenceCommand#executeCommand()} with continueOnError = true
     118     */
     119    @Test
     120    public void testContinueOnErrors() {
     121        TestCommand command1 = new TestCommand(null);
     122        FailingCommand command2 = new FailingCommand();
     123        TestCommand command3 = new TestCommand(null);
     124        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3));
     125        command.continueOnError = true;
     126        assertTrue(command.executeCommand());
     127        assertTrue(command1.executed);
     128        assertTrue(command3.executed);
     129        command.undoCommand();
     130        assertFalse(command1.executed);
     131        // Don't check command2 executed state as it's possible but not necessary to undo failed commands
     132        assertFalse(command3.executed);
     133    }
     134
     135    /**
    101136     * Test {@link SequenceCommand#undoCommand()}
    102137     */
    103138    @Test
     
    228263        }
    229264
    230265    }
     266
     267    private static class FailingCommand extends TestCommand {
     268
     269        FailingCommand() {
     270            super(null);
     271        }
     272
     273        @Override
     274        public boolean executeCommand() {
     275            executed = true;
     276            return false;
     277        }
     278
     279        @Override
     280        public void undoCommand() {
     281            assertTrue("Cannot undo without execute", executed);
     282            executed = false;
     283        }
     284
     285        @Override
     286        public String toString() {
     287            return "FailingCommand";
     288        }
     289
     290    }
     291
    231292}