Skip to content

Commit

Permalink
Add tests in EditCommandTest
Browse files Browse the repository at this point in the history
  • Loading branch information
potaotototo committed Oct 25, 2024
1 parent 099e80f commit 6843c97
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/tuteez/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6843c97

Please sign in to comment.