diff --git a/src/test/java/tuteez/logic/commands/EditCommandTest.java b/src/test/java/tuteez/logic/commands/EditCommandTest.java index 6d59369e01f..bcbd99dc15c 100644 --- a/src/test/java/tuteez/logic/commands/EditCommandTest.java +++ b/src/test/java/tuteez/logic/commands/EditCommandTest.java @@ -28,6 +28,8 @@ import tuteez.testutil.EditPersonDescriptorBuilder; import tuteez.testutil.PersonBuilder; +import java.util.Optional; + /** * Contains integration tests (interaction with the Model) and unit tests for EditCommand. */ @@ -146,6 +148,41 @@ public void execute_invalidPersonIndexFilteredList_failure() { assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } + @Test + public void execute_editLastViewedPerson_success() { + Person originalPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person editedPerson = new PersonBuilder(originalPerson).withName(VALID_NAME_BOB).build(); + EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); + EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(originalPerson, editedPerson); + expectedModel.updateLastViewedPerson(editedPerson); + + String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + + assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_editNonLastViewedPerson_noUpdateLastViewed() { + Person lastViewedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + model.updateLastViewedPerson(lastViewedPerson); + + Person personToEdit = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased()); + Person editedPerson = new PersonBuilder(personToEdit).withName(VALID_NAME_BOB).build(); + EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); + EditCommand editCommand = new EditCommand(INDEX_SECOND_PERSON, descriptor); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(personToEdit, editedPerson); + expectedModel.updateLastViewedPerson(lastViewedPerson); + + String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + + assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); + } + @Test public void equals() { final EditCommand standardCommand = new EditCommand(INDEX_FIRST_PERSON, DESC_AMY);