Skip to content

Commit

Permalink
EditCommandTest: add integration tests with Undo/RedoCommand
Browse files Browse the repository at this point in the history
EditCommandTest does not have any integration tests for the interaction
with UndoCommand and RedoCommand on an unfiltered list.

Let's add integration tests for the interaction of EditCommand with
UndoCommand and RedoCommand on an unfiltered list.
  • Loading branch information
yamidark committed Feb 11, 2018
1 parent 9d13c66 commit c9ff642
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,46 @@ public void execute_invalidPersonIndexFilteredList_failure() {
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

@Test
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception {
UndoRedoStack undoRedoStack = new UndoRedoStack();
UndoCommand undoCommand = prepareUndoCommand(model, undoRedoStack);
RedoCommand redoCommand = prepareRedoCommand(model, undoRedoStack);
Person editedPerson = new PersonBuilder().build();
Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build();
EditCommand editCommand = prepareCommand(INDEX_FIRST_PERSON, descriptor);
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs());

// edit -> first person edited
editCommand.execute();
undoRedoStack.push(editCommand);

// undo -> reverts addressbook back to previous state and filtered person list to show all persons
assertCommandSuccess(undoCommand, model, UndoCommand.MESSAGE_SUCCESS, expectedModel);

// redo -> same first person edited again
expectedModel.updatePerson(personToEdit, editedPerson);
assertCommandSuccess(redoCommand, model, RedoCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void executeUndoRedo_invalidIndexUnfilteredList_failure() {
UndoRedoStack undoRedoStack = new UndoRedoStack();
UndoCommand undoCommand = prepareUndoCommand(model, undoRedoStack);
RedoCommand redoCommand = prepareRedoCommand(model, undoRedoStack);
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build();
EditCommand editCommand = prepareCommand(outOfBoundIndex, descriptor);

// execution failed -> editCommand not pushed into undoRedoStack
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);

// no commands in undoRedoStack -> undoCommand and redoCommand fail
assertCommandFailure(undoCommand, model, UndoCommand.MESSAGE_FAILURE);
assertCommandFailure(redoCommand, model, RedoCommand.MESSAGE_FAILURE);
}

/**
* 1. Edits a {@code Person} from a filtered list.
* 2. Undo the edit.
Expand Down

0 comments on commit c9ff642

Please sign in to comment.