Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
potaotototo committed Oct 29, 2024
1 parent 8bb31e9 commit 90c28ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/test/java/tuteez/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public void updateLastViewedPerson(Person personOnDisplay) {
throw new AssertionError("This method should not be called.");
}

@Override
public void removeLastViewedPerson() {
throw new AssertionError("This method should not be called.");
}

@Override
public Person findPersonByName(Name name) {
throw new AssertionError("This method should not be called.");
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/tuteez/logic/commands/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,52 @@ public void execute_invalidName_throwsCommandException() {
assertCommandFailure(deleteCommand, model, expectedMessage);
}

@Test
public void execute_deleteLastViewedPerson_removesLastViewedPerson() {
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());

model.updateLastViewedPerson(personToDelete);
expectedModel.updateLastViewedPerson(personToDelete);

DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(personToDelete));

expectedModel.deletePerson(personToDelete);
expectedModel.removeLastViewedPerson();

assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);

// Verify last viewed person was removed
assertFalse(model.getLastViewedPerson().get().isPresent(),
"Expected last viewed person to be removed after deleting the viewed person");
}

@Test
public void execute_deleteNonLastViewedPerson_keepsLastViewedPerson() {
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person lastViewedPerson = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());

model.updateLastViewedPerson(lastViewedPerson);
expectedModel.updateLastViewedPerson(lastViewedPerson);

DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(personToDelete));

expectedModel.deletePerson(personToDelete);

assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);

// Verify last viewed person was not removed
assertTrue(model.getLastViewedPerson().get().isPresent(),
"Expected last viewed person to be retained when deleting a different person");
assertEquals(lastViewedPerson, model.getLastViewedPerson().get().get(),
"Expected last viewed person to remain unchanged");
}

@Test
public void equals() {
DeleteCommand deleteFirstCommand = new DeleteCommand(INDEX_FIRST_PERSON);
Expand Down

0 comments on commit 90c28ea

Please sign in to comment.