forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for MedicalCertificateCommand and ReferralLetterCommand
- Loading branch information
Showing
9 changed files
with
253 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,5 +67,6 @@ <h1> | |
} | ||
#contentTable tr:nth-child(even) { | ||
background-color: #f2f2f2; | ||
border-style: groove; | ||
} | ||
</style> |
105 changes: 105 additions & 0 deletions
105
src/test/java/seedu/address/logic/commands/MedicalCertificateCommandTest.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.address.logic.commands; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import static seedu.address.logic.commands.QueueCommandTestUtil.assertUniqueFileInFilteredFileList; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.fileCleanUp; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.generateFileName; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.generateServedPatientList; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.PatientQueue; | ||
import seedu.address.model.PatientQueueManager; | ||
import seedu.address.model.ServedPatientList; | ||
import seedu.address.model.ServedPatientListManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.CurrentPatient; | ||
import seedu.address.testutil.TypicalPersons; | ||
|
||
public class MedicalCertificateCommandTest { | ||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private PatientQueue patientQueue; | ||
private CurrentPatient currentPatient; | ||
private ServedPatientList servedPatientList; | ||
private CommandHistory commandHistory; | ||
|
||
@Before | ||
public void setUp() { | ||
patientQueue = new PatientQueueManager(); | ||
currentPatient = new CurrentPatient(); | ||
servedPatientList = new ServedPatientListManager(); | ||
commandHistory = new CommandHistory(); | ||
model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_validServedPatient_mcMessageSuccess() throws Exception { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
String expectedMessage = MedicalCertificateCommand.MESSAGE_GENERATE_MC_SUCCESS; | ||
MedicalCertificateCommand mcCommand = new MedicalCertificateCommand(INDEX_FIRST_PERSON); | ||
CommandResult commandResult = mcCommand.execute(model, patientQueue, | ||
currentPatient, servedPatientList, commandHistory); | ||
File file = mcCommand.getMc().getFile(); | ||
fileCleanUp(file); | ||
assertEquals(expectedMessage, commandResult.feedbackToUser); | ||
} | ||
|
||
@Test | ||
public void execute_servedPatientListEmpty_commandExceptionThrown() throws Exception { | ||
thrown.expect(CommandException.class); | ||
servedPatientList = generateServedPatientList(); | ||
new MedicalCertificateCommand(INDEX_FIRST_PERSON).execute(model, patientQueue, | ||
currentPatient, servedPatientList, commandHistory); | ||
} | ||
|
||
@Test | ||
public void execute_mcFileName_mcGenerationSuccess() throws Exception { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
MedicalCertificateCommand mcCommand = new MedicalCertificateCommand(INDEX_FIRST_PERSON); | ||
mcCommand.execute(model, patientQueue, currentPatient, servedPatientList, commandHistory); | ||
String fileType = mcCommand.getMc().FILE_TYPE; | ||
String fileName = generateFileName(fileType, TypicalPersons.ALICE); | ||
assertUniqueFileInFilteredFileList(fileName); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
MedicalCertificateCommand mcAliceCommand = new MedicalCertificateCommand(INDEX_FIRST_PERSON); | ||
MedicalCertificateCommand mcBobCommand = new MedicalCertificateCommand(INDEX_SECOND_PERSON); | ||
|
||
// same object -> returns true | ||
assertTrue(mcAliceCommand.equals(mcAliceCommand)); | ||
|
||
// same values -> returns true | ||
MedicalCertificateCommand mcAliceCommandCopy = new MedicalCertificateCommand(INDEX_FIRST_PERSON); | ||
assertTrue(mcAliceCommand.equals(mcAliceCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(mcAliceCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(mcAliceCommand.equals(null)); | ||
|
||
// different patient -> returns false | ||
assertFalse(mcAliceCommand.equals(mcBobCommand)); | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
src/test/java/seedu/address/logic/commands/ReferralLetterCommandTest.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.address.logic.commands; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import static seedu.address.logic.commands.QueueCommandTestUtil.assertUniqueFileInFilteredFileList; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.fileCleanUp; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.generateFileName; | ||
import static seedu.address.logic.commands.QueueCommandTestUtil.generateServedPatientList; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.PatientQueue; | ||
import seedu.address.model.PatientQueueManager; | ||
import seedu.address.model.ServedPatientList; | ||
import seedu.address.model.ServedPatientListManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.CurrentPatient; | ||
import seedu.address.testutil.TypicalPersons; | ||
|
||
public class ReferralLetterCommandTest { | ||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private PatientQueue patientQueue; | ||
private CurrentPatient currentPatient; | ||
private ServedPatientList servedPatientList; | ||
private CommandHistory commandHistory; | ||
|
||
@Before | ||
public void setUp() { | ||
patientQueue = new PatientQueueManager(); | ||
currentPatient = new CurrentPatient(); | ||
servedPatientList = new ServedPatientListManager(); | ||
commandHistory = new CommandHistory(); | ||
model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
} | ||
|
||
@Test | ||
public void execute_validServedPatient_referralMessageSuccess() throws Exception { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
String expectedMessage = ReferralLetterCommand.MESSAGE_GENERATE_REFERRAL_SUCCESS; | ||
ReferralLetterCommand referralLetterCommand = new ReferralLetterCommand(INDEX_FIRST_PERSON); | ||
CommandResult commandResult = referralLetterCommand.execute(model, patientQueue, | ||
currentPatient, servedPatientList, commandHistory); | ||
File file = referralLetterCommand.getRl().getFile(); | ||
fileCleanUp(file); | ||
assertEquals(expectedMessage, commandResult.feedbackToUser); | ||
} | ||
|
||
@Test | ||
public void execute_servedPatientListEmpty_commandExceptionThrown() throws Exception { | ||
thrown.expect(CommandException.class); | ||
servedPatientList = generateServedPatientList(); | ||
new ReferralLetterCommand(INDEX_FIRST_PERSON).execute(model, patientQueue, | ||
currentPatient, servedPatientList, commandHistory); | ||
} | ||
|
||
@Test | ||
public void execute_mcFileName_mcGenerationSuccess() throws Exception { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
ReferralLetterCommand referralLetterCommand = new ReferralLetterCommand(INDEX_FIRST_PERSON); | ||
referralLetterCommand.execute(model, patientQueue, currentPatient, servedPatientList, commandHistory); | ||
String fileType = referralLetterCommand.getRl().FILE_TYPE; | ||
String fileName = generateFileName(fileType, TypicalPersons.ALICE); | ||
assertUniqueFileInFilteredFileList(fileName); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB); | ||
ReferralLetterCommand rlAliceCommand = new ReferralLetterCommand(INDEX_FIRST_PERSON); | ||
ReferralLetterCommand rlBobCommand = new ReferralLetterCommand(INDEX_SECOND_PERSON); | ||
|
||
// same object -> returns true | ||
assertTrue(rlAliceCommand.equals(rlAliceCommand)); | ||
|
||
// same values -> returns true | ||
ReferralLetterCommand rlAliceCommandCopy = new ReferralLetterCommand(INDEX_FIRST_PERSON); | ||
assertTrue(rlAliceCommand.equals(rlAliceCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(rlAliceCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(rlAliceCommand.equals(null)); | ||
|
||
// different patient -> returns false | ||
assertFalse(rlAliceCommand.equals(rlBobCommand)); | ||
} | ||
} |