forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nus-cs2103-AY1819S2#89 from wfxronald/docs
Update the tests for remall and others. Closes nus-cs2103-AY1819S2#77
- Loading branch information
Showing
8 changed files
with
302 additions
and
4 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
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
204 changes: 204 additions & 0 deletions
204
src/test/java/seedu/giatros/logic/commands/RemallCommandTest.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,204 @@ | ||
package seedu.giatros.logic.commands; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static seedu.giatros.logic.commands.CommandTestUtil.VALID_ALLERGY_AMY; | ||
import static seedu.giatros.logic.commands.CommandTestUtil.VALID_ALLERGY_BOB; | ||
import static seedu.giatros.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.giatros.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.giatros.logic.commands.CommandTestUtil.showPatientAtIndex; | ||
import static seedu.giatros.testutil.TypicalIndexes.INDEX_FIRST_PATIENT; | ||
import static seedu.giatros.testutil.TypicalIndexes.INDEX_SECOND_PATIENT; | ||
import static seedu.giatros.testutil.TypicalPatients.getTypicalGiatrosBook; | ||
|
||
import java.util.HashSet; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.giatros.commons.core.Messages; | ||
import seedu.giatros.commons.core.index.Index; | ||
import seedu.giatros.logic.CommandHistory; | ||
import seedu.giatros.model.GiatrosBook; | ||
import seedu.giatros.model.Model; | ||
import seedu.giatros.model.ModelManager; | ||
import seedu.giatros.model.UserPrefs; | ||
import seedu.giatros.model.allergy.Allergy; | ||
import seedu.giatros.model.patient.Patient; | ||
import seedu.giatros.testutil.PatientBuilder; | ||
|
||
public class RemallCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalGiatrosBook(), new UserPrefs()); | ||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
@Test | ||
public void execute_removeAllergyUnfilteredList_success() { | ||
Patient firstPatient = model.getFilteredPatientList().get(INDEX_FIRST_PATIENT.getZeroBased()); | ||
Patient editedPatient = new Patient(firstPatient.getName(), firstPatient.getPhone(), firstPatient.getEmail(), | ||
firstPatient.getAddress(), new HashSet<>()); | ||
|
||
RemallCommand remallCommand = new RemallCommand(INDEX_FIRST_PATIENT, firstPatient.getAllergies()); | ||
|
||
String expectedMessage = String.format(RemallCommand.MESSAGE_REMOVE_ALLERGY_SUCCESS, editedPatient); | ||
|
||
Model expectedModel = new ModelManager(new GiatrosBook(model.getGiatrosBook()), new UserPrefs()); | ||
expectedModel.setPatient(firstPatient, editedPatient); | ||
expectedModel.commitGiatrosBook(); | ||
|
||
assertCommandSuccess(remallCommand, model, commandHistory, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_removeNonExistentAllergyUnfilteredList_success() { | ||
Patient firstPatient = model.getFilteredPatientList().get(INDEX_FIRST_PATIENT.getZeroBased()); | ||
Patient editedPatient = new PatientBuilder(firstPatient).build(); | ||
|
||
RemallCommand remallCommand = new RemallCommand(INDEX_FIRST_PATIENT, new Allergy("randomAllergy")); | ||
|
||
String expectedMessage = String.format(RemallCommand.MESSAGE_REMOVE_ALLERGY_FAILURE, editedPatient); | ||
|
||
Model expectedModel = new ModelManager(new GiatrosBook(model.getGiatrosBook()), new UserPrefs()); | ||
expectedModel.setPatient(firstPatient, editedPatient); | ||
expectedModel.commitGiatrosBook(); | ||
|
||
assertCommandSuccess(remallCommand, model, commandHistory, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_filteredList_success() { | ||
showPatientAtIndex(model, INDEX_FIRST_PATIENT); | ||
|
||
Patient firstPatient = model.getFilteredPatientList().get(INDEX_FIRST_PATIENT.getZeroBased()); | ||
Patient editedPatient = new Patient(firstPatient.getName(), firstPatient.getPhone(), firstPatient.getEmail(), | ||
firstPatient.getAddress(), new HashSet<>()); | ||
|
||
RemallCommand remallCommand = new RemallCommand(INDEX_FIRST_PATIENT, firstPatient.getAllergies()); | ||
|
||
String expectedMessage = String.format(RemallCommand.MESSAGE_REMOVE_ALLERGY_SUCCESS, editedPatient); | ||
|
||
Model expectedModel = new ModelManager(new GiatrosBook(model.getGiatrosBook()), new UserPrefs()); | ||
expectedModel.setPatient(firstPatient, editedPatient); | ||
expectedModel.commitGiatrosBook(); | ||
|
||
assertCommandSuccess(remallCommand, model, commandHistory, expectedMessage, expectedModel); | ||
} | ||
|
||
@Test | ||
public void execute_invalidPatientIndexUnfilteredList_failure() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPatientList().size() + 1); | ||
RemallCommand remallCommand = new RemallCommand(outOfBoundIndex, new Allergy(VALID_ALLERGY_BOB)); | ||
|
||
assertCommandFailure(remallCommand, model, commandHistory, Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX); | ||
} | ||
|
||
/** | ||
* Edit filtered list where index is larger than size of filtered list, | ||
* but smaller than size of giatros book | ||
*/ | ||
@Test | ||
public void execute_invalidPatientIndexFilteredList_failure() { | ||
showPatientAtIndex(model, INDEX_FIRST_PATIENT); | ||
Index outOfBoundIndex = INDEX_SECOND_PATIENT; | ||
// ensures that outOfBoundIndex is still in bounds of giatros book list | ||
assertTrue(outOfBoundIndex.getZeroBased() < model.getGiatrosBook().getPatientList().size()); | ||
|
||
RemallCommand remallCommand = new RemallCommand(outOfBoundIndex, new Allergy(VALID_ALLERGY_BOB)); | ||
|
||
assertCommandFailure(remallCommand, model, commandHistory, Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX); | ||
} | ||
|
||
@Test | ||
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception { | ||
Patient patientToModify = model.getFilteredPatientList().get(INDEX_FIRST_PATIENT.getZeroBased()); | ||
Patient modifiedPatient = new Patient(patientToModify.getName(), patientToModify.getPhone(), | ||
patientToModify.getEmail(), patientToModify.getAddress(), new HashSet<>()); | ||
|
||
RemallCommand remallCommand = new RemallCommand(INDEX_FIRST_PATIENT, patientToModify.getAllergies()); | ||
|
||
Model expectedModel = new ModelManager(model.getGiatrosBook(), new UserPrefs()); | ||
expectedModel.setPatient(patientToModify, modifiedPatient); | ||
expectedModel.commitGiatrosBook(); | ||
|
||
// remall -> first patient allergy changed | ||
remallCommand.execute(model, commandHistory); | ||
|
||
// undo -> reverts giatrosbook back to previous state and filtered patient list to show all patients | ||
expectedModel.undoGiatrosBook(); | ||
assertCommandSuccess(new UndoCommand(), model, commandHistory, UndoCommand.MESSAGE_SUCCESS, expectedModel); | ||
|
||
// redo -> same first patient modified again | ||
expectedModel.redoGiatrosBook(); | ||
assertCommandSuccess(new RedoCommand(), model, commandHistory, RedoCommand.MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
public void executeUndoRedo_invalidIndexUnfilteredList_failure() { | ||
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPatientList().size() + 1); | ||
RemallCommand remallCommand = new RemallCommand(outOfBoundIndex, new Allergy("randomAllergy")); | ||
|
||
// execution failed -> giatros book state not added into model | ||
assertCommandFailure(remallCommand, model, commandHistory, Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX); | ||
|
||
// single giatros book state in model -> undoCommand and redoCommand fail | ||
assertCommandFailure(new UndoCommand(), model, commandHistory, UndoCommand.MESSAGE_FAILURE); | ||
assertCommandFailure(new RedoCommand(), model, commandHistory, RedoCommand.MESSAGE_FAILURE); | ||
} | ||
|
||
/** | ||
* 1. Modifies {@code Patient#allergy} from a filtered list. | ||
* 2. Undo the modification. | ||
* 3. The unfiltered list should be shown now. Verify that the index of the previously modified patient in the | ||
* unfiltered list is different from the index at the filtered list. | ||
* 4. Redo the modification. This ensures {@code RedoCommand} modifies the patient object regardless of indexing. | ||
*/ | ||
@Test | ||
public void executeUndoRedo_validIndexFilteredList_samePatientDeleted() throws Exception { | ||
showPatientAtIndex(model, INDEX_SECOND_PATIENT); | ||
|
||
Patient patientToModify = model.getFilteredPatientList().get(INDEX_FIRST_PATIENT.getZeroBased()); | ||
Patient modifiedPatient = new Patient(patientToModify.getName(), patientToModify.getPhone(), | ||
patientToModify.getEmail(), patientToModify.getAddress(), new HashSet<>()); | ||
|
||
RemallCommand remallCommand = new RemallCommand(INDEX_FIRST_PATIENT, patientToModify.getAllergies()); | ||
Model expectedModel = new ModelManager(model.getGiatrosBook(), new UserPrefs()); | ||
|
||
expectedModel.setPatient(patientToModify, modifiedPatient); | ||
expectedModel.commitGiatrosBook(); | ||
|
||
// remall -> modifies second patient in unfiltered patient list / first patient in filtered patient list | ||
remallCommand.execute(model, commandHistory); | ||
|
||
// undo -> reverts giatrosbook back to previous state and filtered patient list to show all patients | ||
expectedModel.undoGiatrosBook(); | ||
assertCommandSuccess(new UndoCommand(), model, commandHistory, UndoCommand.MESSAGE_SUCCESS, expectedModel); | ||
|
||
// redo -> modifies same second patient in unfiltered patient list | ||
expectedModel.redoGiatrosBook(); | ||
assertCommandSuccess(new RedoCommand(), model, commandHistory, RedoCommand.MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
final RemallCommand standardCommand = new RemallCommand(INDEX_FIRST_PATIENT, new Allergy(VALID_ALLERGY_AMY)); | ||
|
||
// same values -> returns true | ||
RemallCommand commandWithSameValues = new RemallCommand(INDEX_FIRST_PATIENT, new Allergy(VALID_ALLERGY_AMY)); | ||
assertTrue(standardCommand.equals(commandWithSameValues)); | ||
|
||
// same object -> returns true | ||
assertTrue(standardCommand.equals(standardCommand)); | ||
|
||
// null -> returns false | ||
assertFalse(standardCommand.equals(null)); | ||
|
||
// different types -> returns false | ||
assertFalse(standardCommand.equals(new ClearCommand())); | ||
|
||
// different index -> returns false | ||
assertFalse(standardCommand.equals(new RemallCommand(INDEX_SECOND_PATIENT, new Allergy(VALID_ALLERGY_AMY)))); | ||
|
||
// different descriptor -> returns false | ||
assertFalse(standardCommand.equals(new RemallCommand(INDEX_FIRST_PATIENT, new Allergy(VALID_ALLERGY_BOB)))); | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
src/test/java/seedu/giatros/logic/parser/RemallCommandParserTest.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,54 @@ | ||
package seedu.giatros.logic.parser; | ||
|
||
import static seedu.giatros.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.giatros.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.giatros.logic.parser.CliSyntax.PREFIX_ALLERGY; | ||
import static seedu.giatros.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.giatros.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.giatros.testutil.TypicalIndexes.INDEX_FIRST_PATIENT; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.giatros.commons.core.index.Index; | ||
import seedu.giatros.logic.commands.RemallCommand; | ||
import seedu.giatros.model.allergy.Allergy; | ||
|
||
public class RemallCommandParserTest { | ||
|
||
private RemallCommandParser parser = new RemallCommandParser(); | ||
private final String nonEmptyAllergy = "someAllergy"; | ||
|
||
@Test | ||
public void parse_allFieldsPresent_success() { | ||
// adding non-empty allergy | ||
Index index = INDEX_FIRST_PATIENT; | ||
String input = index.getOneBased() + " " + PREFIX_ALLERGY + nonEmptyAllergy; | ||
assertParseSuccess(parser, input, new RemallCommand(INDEX_FIRST_PATIENT, new Allergy(nonEmptyAllergy))); | ||
} | ||
|
||
@Test | ||
public void parse_invalidFormat_failure() { | ||
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemallCommand.MESSAGE_USAGE); | ||
|
||
// no parameters provided | ||
assertParseFailure(parser, "", expectedMessage); | ||
|
||
// no index provided | ||
String input = PREFIX_ALLERGY + " " + nonEmptyAllergy; | ||
assertParseFailure(parser, input, expectedMessage); | ||
|
||
// no allergy provided | ||
input = INDEX_FIRST_PATIENT.getOneBased() + " "; | ||
assertParseFailure(parser, input, String.format(RemallCommand.MESSAGE_INCORRECT_ALLERGY)); | ||
|
||
// no prefix provided | ||
input = INDEX_FIRST_PATIENT.getOneBased() + " " + nonEmptyAllergy; | ||
assertParseFailure(parser, input, expectedMessage); | ||
|
||
// invalid prefix specified | ||
input = INDEX_FIRST_PATIENT.getOneBased() + " " + PREFIX_ADDRESS + " " + nonEmptyAllergy; | ||
assertParseFailure(parser, input, expectedMessage); | ||
|
||
} | ||
|
||
} |