forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from dedsecrattle/features/undo
Implement Undo Command
- Loading branch information
Showing
13 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/seedu/edulink/logic/commands/UndoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.edulink.logic.commands; | ||
|
||
import seedu.edulink.logic.Messages; | ||
import seedu.edulink.logic.commands.exceptions.CommandException; | ||
import seedu.edulink.model.Model; | ||
|
||
/** | ||
* Undo the most recent command and revert back to previous state | ||
*/ | ||
public class UndoCommand extends Command { | ||
public static final String COMMAND_WORD = "undo"; | ||
public static final String MESSAGE_USAGE = "Usage: " + COMMAND_WORD; | ||
public static final String MESSAGE_SUCCESS = "Undo Command done Successfully"; | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
if (model.resetToPreviousState()) { | ||
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} else { | ||
throw new CommandException(Messages.MESSAGE_NO_HISTORY_FOUND); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/seedu/edulink/logic/commands/UndoCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package seedu.edulink.logic.commands; | ||
|
||
import static seedu.edulink.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.edulink.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.edulink.logic.Messages; | ||
import seedu.edulink.model.Model; | ||
import seedu.edulink.model.ModelManager; | ||
import seedu.edulink.testutil.TypicalPersons; | ||
|
||
public class UndoCommandTest { | ||
private Model model = new ModelManager(); | ||
|
||
@Test | ||
public void undo_command_failure() { | ||
assertCommandFailure(new UndoCommand(), model, Messages.MESSAGE_NO_HISTORY_FOUND); | ||
} | ||
|
||
@Test | ||
public void add_success() { | ||
model.addPerson(TypicalPersons.ALICE); | ||
Model expected = new ModelManager(); | ||
assertCommandSuccess(new UndoCommand(), model, new CommandResult(UndoCommand.MESSAGE_SUCCESS), expected); | ||
} | ||
|
||
@Test | ||
public void edit_success() { | ||
model.addPerson(TypicalPersons.ALICE); | ||
model.setPerson(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
Model expected = new ModelManager(); | ||
expected.addPerson(TypicalPersons.ALICE); | ||
assertCommandSuccess(new UndoCommand(), model, new CommandResult(UndoCommand.MESSAGE_SUCCESS), expected); | ||
} | ||
|
||
@Test | ||
public void delete_success() { | ||
model.addPerson(TypicalPersons.ALICE); | ||
model.deletePerson(TypicalPersons.ALICE); | ||
Model expected = new ModelManager(); | ||
expected.addPerson(TypicalPersons.ALICE); | ||
assertCommandSuccess(new UndoCommand(), model, new CommandResult(UndoCommand.MESSAGE_SUCCESS), expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters