forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement test cases for MedicalHistory suite of classes (#269)
* Implement test cases for MedicalHistory class * Add more test cases for new methods in Patient class * Add AddMedicalEntryCommand test cases * Add DeleteMedicalEntryCommand test cases * Modify test case * Add more test cases * Add AddMedicalHistoryParserTest test cases * Add testcase for AddMedicalEntryCommandParserTest * Add success case for DeleteMedicalEntryCommandParserTest * Add one failure test case for DeleteMedicalEntryCommandParserTest * Add failure test case to DeleteMedicalEntryCommandTest * Fix checkstyle * Remove comment
- Loading branch information
1 parent
dfe7068
commit 7633504
Showing
16 changed files
with
480 additions
and
33 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
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
85 changes: 85 additions & 0 deletions
85
src/test/java/seedu/docit/logic/commands/AddMedicalEntryCommandTest.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,85 @@ | ||
package seedu.docit.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.docit.testutil.Assert.assertThrows; | ||
import static seedu.docit.testutil.TypicalIndexes.INDEX_FIRST_PATIENT; | ||
import static seedu.docit.testutil.TypicalPatients.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.docit.commons.core.index.Index; | ||
import seedu.docit.logic.commands.exceptions.CommandException; | ||
import seedu.docit.model.AppointmentBook; | ||
import seedu.docit.model.ArchivedAppointmentBook; | ||
import seedu.docit.model.Model; | ||
import seedu.docit.model.ModelManager; | ||
import seedu.docit.model.UserPrefs; | ||
import seedu.docit.model.patient.MedicalHistory; | ||
import seedu.docit.model.patient.Patient; | ||
import seedu.docit.testutil.PatientBuilder; | ||
import seedu.docit.testutil.TypicalPatients; | ||
|
||
public class AddMedicalEntryCommandTest { | ||
private static final String DEFAULT_MEDICAL = "high blood pressure"; | ||
|
||
private final Model model = new ModelManager(getTypicalAddressBook(), new AppointmentBook(), | ||
new ArchivedAppointmentBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void constructor_nullArguments_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new AddMedicalEntryCommand(null, null)); | ||
} | ||
|
||
@Test | ||
public void execute_validMedicalEntry_addSuccessful() throws CommandException { | ||
Patient editedPatient = | ||
new PatientBuilder(getTypicalAddressBook().getPatientOfIndex(INDEX_FIRST_PATIENT)).build(); | ||
|
||
AddMedicalEntryCommand addMedicalEntryCommand = new AddMedicalEntryCommand(INDEX_FIRST_PATIENT, | ||
new MedicalHistory(DEFAULT_MEDICAL)); | ||
|
||
CommandResult commandResult = addMedicalEntryCommand.execute(model); | ||
|
||
CommandResult expectedCommandResult = new CommandResult(AddMedicalEntryCommand.MESSAGE_SUCCESS | ||
+ editedPatient); | ||
|
||
assertEquals(expectedCommandResult, commandResult); | ||
} | ||
|
||
@Test | ||
public void execute_patientToAddDoesNotExist_throwsCommandException() throws CommandException { | ||
int n = getTypicalAddressBook().getPatientList().size(); | ||
Index invalidIndex = Index.fromOneBased(n + 1); | ||
Index otherInvalidIndex = Index.fromZeroBased(n); | ||
|
||
AddMedicalEntryCommand addMedicalEntryCommand = new AddMedicalEntryCommand(invalidIndex, | ||
new MedicalHistory(DEFAULT_MEDICAL)); | ||
AddMedicalEntryCommand otherAddMedicalEntryCommand = new AddMedicalEntryCommand(otherInvalidIndex, | ||
new MedicalHistory(DEFAULT_MEDICAL)); | ||
|
||
assertThrows(CommandException.class, () -> addMedicalEntryCommand.execute(model)); | ||
assertThrows(CommandException.class, () -> otherAddMedicalEntryCommand.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_validMedicalEntryFromEmptyMedicalHistory_addSuccessful() throws CommandException { | ||
Patient targetPatient = | ||
new PatientBuilder(getTypicalAddressBook().getPatientOfIndex(INDEX_FIRST_PATIENT)).build(); | ||
|
||
Patient editedPatient = TypicalPatients.makeEmptyMedicalHistory(targetPatient); | ||
|
||
MedicalHistory toAdd = new MedicalHistory(DEFAULT_MEDICAL); | ||
|
||
model.setPatient(targetPatient, editedPatient); | ||
AddMedicalEntryCommand addMedicalEntryCommand = new AddMedicalEntryCommand(INDEX_FIRST_PATIENT, | ||
toAdd); | ||
CommandResult commandResult = addMedicalEntryCommand.execute(model); | ||
|
||
// testing against really adding it Patient medical history | ||
editedPatient = editedPatient.addMedicalHistory(toAdd); | ||
CommandResult expectedCommandResult = new CommandResult(AddMedicalEntryCommand.MESSAGE_SUCCESS | ||
+ editedPatient); | ||
|
||
assertEquals(expectedCommandResult, commandResult); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/test/java/seedu/docit/logic/commands/DeleteMedicalEntryTest.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,105 @@ | ||
package seedu.docit.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.docit.testutil.Assert.assertThrows; | ||
import static seedu.docit.testutil.TypicalIndexes.INDEX_FIRST_PATIENT; | ||
import static seedu.docit.testutil.TypicalPatients.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.docit.commons.core.index.Index; | ||
import seedu.docit.logic.commands.exceptions.CommandException; | ||
import seedu.docit.model.AppointmentBook; | ||
import seedu.docit.model.ArchivedAppointmentBook; | ||
import seedu.docit.model.Model; | ||
import seedu.docit.model.ModelManager; | ||
import seedu.docit.model.UserPrefs; | ||
import seedu.docit.model.patient.Patient; | ||
import seedu.docit.testutil.PatientBuilder; | ||
import seedu.docit.testutil.TypicalPatients; | ||
|
||
public class DeleteMedicalEntryTest { | ||
private final Model model = new ModelManager(getTypicalAddressBook(), new AppointmentBook(), | ||
new ArchivedAppointmentBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void constructor_nullArguments_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new DeleteMedicalEntryCommand(null, null)); | ||
} | ||
|
||
@Test | ||
public void execute_invalidPatientIndex_throwsCommandException() throws CommandException { | ||
int numberOfPatients = getTypicalAddressBook().getPatientList().size(); | ||
int countOfMedicalEntriesFromFirstPatient = getTypicalAddressBook().getPatientOfIndex(Index.fromOneBased(1)) | ||
.getMedicalHistory().size(); | ||
|
||
Index validMedicalIndex = Index.fromOneBased(countOfMedicalEntriesFromFirstPatient); | ||
|
||
Index invalidPatientIndex = Index.fromOneBased(numberOfPatients + 1); | ||
Index otherInvalidPatientIndex = Index.fromZeroBased(numberOfPatients); | ||
|
||
DeleteMedicalEntryCommand deleteMedicalEntryCommand = | ||
new DeleteMedicalEntryCommand(invalidPatientIndex, validMedicalIndex); | ||
DeleteMedicalEntryCommand otherDeleteMedicalEntryCommand = | ||
new DeleteMedicalEntryCommand(otherInvalidPatientIndex, validMedicalIndex); | ||
|
||
assertThrows(CommandException.class, () -> deleteMedicalEntryCommand.execute(model)); | ||
assertThrows(CommandException.class, () -> otherDeleteMedicalEntryCommand.execute(model)); | ||
} | ||
|
||
// Test for patients who have an existing non-empty medical history but the medical entry specified does not exist | ||
@Test | ||
public void execute_medicalEntryDoesNotExist_throwsCommandException() throws CommandException { | ||
Index validPatientIndex = INDEX_FIRST_PATIENT; | ||
int countOfMedicalEntriesFromFirstPatient = getTypicalAddressBook().getPatientOfIndex(validPatientIndex) | ||
.getMedicalHistory().size(); | ||
|
||
Index tooLargeMedical = Index.fromOneBased(countOfMedicalEntriesFromFirstPatient + 1); | ||
|
||
|
||
DeleteMedicalEntryCommand deleteMedicalEntryCommand = | ||
new DeleteMedicalEntryCommand(validPatientIndex, tooLargeMedical); | ||
|
||
assertThrows(CommandException.class, () -> deleteMedicalEntryCommand.execute(model)); | ||
} | ||
|
||
// Test for patients who have an empty medical history | ||
@Test | ||
public void execute_emptyMedicalHistory_throwsCommandException() throws CommandException { | ||
Index validPatientIndex = INDEX_FIRST_PATIENT; | ||
int countOfMedicalEntriesFromFirstPatient = getTypicalAddressBook().getPatientOfIndex(validPatientIndex) | ||
.getMedicalHistory().size(); | ||
|
||
Patient targetPatient = getTypicalAddressBook().getPatientOfIndex(validPatientIndex); | ||
Patient firstPatient = TypicalPatients.makeEmptyMedicalHistory(targetPatient); | ||
|
||
model.setPatient(targetPatient, firstPatient); | ||
|
||
Index tooLargeMedical = Index.fromOneBased(1); | ||
|
||
DeleteMedicalEntryCommand deleteMedicalEntryCommand = | ||
new DeleteMedicalEntryCommand(validPatientIndex, tooLargeMedical); | ||
|
||
assertThrows(CommandException.class, () -> deleteMedicalEntryCommand.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_validIndexValidPatientIndex_deleteSuccessful() throws CommandException { | ||
Index validPatientIndex = INDEX_FIRST_PATIENT; | ||
Patient firstPatient = | ||
new PatientBuilder(getTypicalAddressBook().getPatientOfIndex(INDEX_FIRST_PATIENT)).build(); | ||
int countOfMedicalEntriesFromFirstPatient = firstPatient.getMedicalHistory().size(); | ||
Index validMedicalIndex = Index.fromOneBased(countOfMedicalEntriesFromFirstPatient); | ||
|
||
DeleteMedicalEntryCommand deleteMedicalEntryCommand = | ||
new DeleteMedicalEntryCommand(validPatientIndex, validMedicalIndex); | ||
CommandResult commandResult = deleteMedicalEntryCommand.execute(model); | ||
|
||
firstPatient = firstPatient.deleteMedicalHistory(validMedicalIndex); | ||
CommandResult expectedCommandResult = new CommandResult(DeleteMedicalEntryCommand.MESSAGE_SUCCESS | ||
+ firstPatient); | ||
|
||
assertEquals(expectedCommandResult, commandResult); | ||
} | ||
|
||
} |
Oops, something went wrong.