diff --git a/src/main/java/seedu/address/logic/commands/RedoCommand.java b/src/main/java/seedu/address/logic/commands/RedoCommand.java index cc496bdc12e..7ba49bdfc41 100644 --- a/src/main/java/seedu/address/logic/commands/RedoCommand.java +++ b/src/main/java/seedu/address/logic/commands/RedoCommand.java @@ -16,7 +16,7 @@ public class RedoCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Redo the most recent command that was undone."; - private static final String MESSAGE_SUCCESS = + public static final String MESSAGE_SUCCESS = "The last command that modified the employee list has been redone!\n" + "Successfully redone the following command: %1$s"; diff --git a/src/main/java/seedu/address/logic/commands/UndoCommand.java b/src/main/java/seedu/address/logic/commands/UndoCommand.java index 1b764bd3816..105b83bb9e8 100644 --- a/src/main/java/seedu/address/logic/commands/UndoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UndoCommand.java @@ -16,7 +16,7 @@ public class UndoCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Undo the most recent command that modified the employee list."; - private static final String MESSAGE_SUCCESS = + public static final String MESSAGE_SUCCESS = "The last command that modified the employee list has been undone!\n" + "Successfully undone the following command: %1$s"; diff --git a/src/main/java/seedu/address/model/AddressBookList.java b/src/main/java/seedu/address/model/AddressBookList.java index b67a27ffc89..4008ee2acb3 100644 --- a/src/main/java/seedu/address/model/AddressBookList.java +++ b/src/main/java/seedu/address/model/AddressBookList.java @@ -8,9 +8,9 @@ * Represents the history of AddressBook to allow undo and redo. */ public class AddressBookList extends ArrayList { - private static final String REDO_ERROR_MESSAGE = "There is no command to redo! " + public static final String REDO_ERROR_MESSAGE = "There is no command to redo! " + "The command to be redone need to previously modified the employee list."; - private static final String UNDO_ERROR_MESSAGE = "There is no command to undo! " + public static final String UNDO_ERROR_MESSAGE = "There is no command to undo! " + "The command to be undone need to previously modified the employee list."; private ArrayList pastCommands = new ArrayList(); diff --git a/src/test/java/seedu/address/logic/commands/RedoCommandTest.java b/src/test/java/seedu/address/logic/commands/RedoCommandTest.java new file mode 100644 index 00000000000..160d873cae8 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/RedoCommandTest.java @@ -0,0 +1,32 @@ +package seedu.address.logic.commands; + +import org.junit.jupiter.api.Test; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; + +import seedu.address.model.AddressBookList; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; + +public class RedoCommandTest { + private Model model = new ModelManager(); + private RedoCommand command = new RedoCommand(); + + @Test + public void execute_redo_success() { + model.addPerson(ALICE); + model.addCommandText("add Alice"); + model.addPerson(BENSON); + model.addCommandText("add Benson"); + model.undo(); + assertCommandSuccess(command, model, String.format(RedoCommand.MESSAGE_SUCCESS, "add Benson"), model); + } + + @Test + public void execute_redo_failure() { + assertCommandFailure(command, model, AddressBookList.REDO_ERROR_MESSAGE); + } +} diff --git a/src/test/java/seedu/address/logic/commands/UndoCommandTest.java b/src/test/java/seedu/address/logic/commands/UndoCommandTest.java new file mode 100644 index 00000000000..235dfe8b297 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/UndoCommandTest.java @@ -0,0 +1,31 @@ +package seedu.address.logic.commands; + +import org.junit.jupiter.api.Test; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; + +import seedu.address.model.AddressBookList; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; + +public class UndoCommandTest { + private Model model = new ModelManager(); + private UndoCommand command = new UndoCommand(); + + @Test + public void execute_undo_success() { + model.addPerson(ALICE); + model.addCommandText("add Alice"); + model.addPerson(BENSON); + model.addCommandText("add Benson"); + assertCommandSuccess(command, model, String.format(UndoCommand.MESSAGE_SUCCESS, "add Benson"), model); + } + + @Test + public void execute_undo_failure() { + assertCommandFailure(command, model, AddressBookList.UNDO_ERROR_MESSAGE); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 728202a8bb9..1d6b3102373 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -25,6 +25,8 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.LeaveCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RedoCommand; +import seedu.address.logic.commands.UndoCommand; import seedu.address.logic.commands.ViewLeaveCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; @@ -125,4 +127,13 @@ public void parseCommand_birthday_withoutMonth() throws Exception { assertTrue(parser.parseCommand(BirthdayCommand.COMMAND_WORD) instanceof BirthdayCommand); } + @Test + public void parseCommand_undo() throws Exception { + assertTrue(parser.parseCommand(UndoCommand.COMMAND_WORD) instanceof UndoCommand); + } + + @Test + public void parseCommand_redo() throws Exception { + assertTrue(parser.parseCommand(RedoCommand.COMMAND_WORD) instanceof RedoCommand); + } } diff --git a/src/test/java/seedu/address/model/AddressBookListTest.java b/src/test/java/seedu/address/model/AddressBookListTest.java index b8be7728bad..9ef9f337cda 100644 --- a/src/test/java/seedu/address/model/AddressBookListTest.java +++ b/src/test/java/seedu/address/model/AddressBookListTest.java @@ -13,6 +13,8 @@ public void undo_success() { addressBookList.add(new AddressBook()); addressBookList.add(new AddressBook()); assertEquals(addressBookList.undo(), new AddressBook()); + addressBookList.add(new AddressBook()); + assertEquals(addressBookList.undo(), new AddressBook()); } @Test