Skip to content

Commit

Permalink
Add tests for MedicalCertificateCommand and ReferralLetterCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
clawyq committed Oct 23, 2018
2 parents aae557c + 639e211 commit be95cff
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class MedicalCertificateCommand extends QueueCommand {
+ " NRIC of patient, and duration of medical leave. \n"
+ "Example: " + COMMAND_WORD + "<Served patient's index>";

public static final String MESSAGE_SUCCESS = "MC generated for patient!";
public static final String MESSAGE_GENERATE_MC_SUCCESS = "MC generated for patient!";

private MedicalCertificate mc;
private final Index index;
private String generatedResult;

/**
* Creates a MedicalCertificateCommand for the {@code servedPatient} specified by {@code index}
Expand All @@ -50,14 +50,13 @@ public CommandResult execute(Model model, PatientQueue patientQueue, CurrentPati
if (index.getZeroBased() >= servedPatientList.getServedPatientListLength()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
final MedicalCertificate mc;

ServedPatient servedPatient = servedPatientList.selectServedPatient(index);
mc = new MedicalCertificate(servedPatient);
mc.generateDocument();

EventsCenter.getInstance().post(new ShowPatientListEvent());
return new CommandResult(String.format(MESSAGE_SUCCESS));
return new CommandResult(String.format(MESSAGE_GENERATE_MC_SUCCESS));
}

@Override
Expand All @@ -66,4 +65,8 @@ public boolean equals(Object other) {
|| (other instanceof MedicalCertificateCommand // instanceof handles nulls
&& index.equals(((MedicalCertificateCommand) other).index)); // state check
}

public MedicalCertificate getMc() {
return mc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class ReceiptCommand extends QueueCommand {
private Receipt receipt;
private final Index index;


/**
* Creates a ReceiptCommand for the {@code servedPatient} specified by {@code index}
*/
Expand Down Expand Up @@ -67,8 +66,4 @@ public boolean equals(Object other) {
public Receipt getReceipt() {
return receipt;
}

public void setReceipt(Receipt receipt) {
this.receipt = receipt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public class ReferralLetterCommand extends QueueCommand {
+ " and information written by the issuing doctor. \n"
+ "Example: " + COMMAND_WORD + "<person's index>";

public static final String MESSAGE_SUCCESS = "Referral letter generated for patient!";
public static final String MESSAGE_GENERATE_REFERRAL_SUCCESS = "Referral letter generated for patient!";

private ReferralLetter rl;
private final Index index;

/**
Expand All @@ -49,14 +50,13 @@ public CommandResult execute(Model model, PatientQueue patientQueue, CurrentPati
if (index.getZeroBased() >= servedPatientList.getServedPatientListLength()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
final ReferralLetter rl;

ServedPatient servedPatient = servedPatientList.selectServedPatient(index);
rl = new ReferralLetter(servedPatient);
rl.generateDocument();

EventsCenter.getInstance().post(new ShowPatientListEvent());
return new CommandResult(String.format(MESSAGE_SUCCESS));
return new CommandResult(String.format(MESSAGE_GENERATE_REFERRAL_SUCCESS));
}

@Override
Expand All @@ -65,4 +65,8 @@ public boolean equals(Object other) {
|| (other instanceof ReferralLetterCommand // instanceof handles nulls
&& index.equals(((ReferralLetterCommand) other).index)); // state check
}

public ReferralLetter getRl() {
return rl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* is relevant to the medical certificate.
*/
public class MedicalCertificate extends Document {
private static final String FILE_TYPE = "Medical Certificate";
public static final String FILE_TYPE = "Medical Certificate";
private final String mcContent;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* relevant to the referral letter.
*/
public class ReferralLetter extends Document {
private static final String FILE_TYPE = "Referral Letter";
public static final String FILE_TYPE = "Referral Letter";
private final String referralContent;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/view/Documents/DocumentTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ <h1>
}
#contentTable tr:nth-child(even) {
background-color: #f2f2f2;
border-style: groove;
}
</style>
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));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;
Expand Down Expand Up @@ -76,5 +79,27 @@ public void execute_receiptFileName_receiptGenerationSuccess() throws Exception
String fileName = generateFileName(fileType, TypicalPersons.ALICE);
assertUniqueFileInFilteredFileList(fileName);
}
}

@Test
public void equals() {
servedPatientList = generateServedPatientList(TypicalPersons.ALICE, TypicalPersons.BOB);
ReceiptCommand receiptAliceCommand = new ReceiptCommand(INDEX_FIRST_PERSON);
ReceiptCommand receiptBobCommand = new ReceiptCommand(INDEX_SECOND_PERSON);

// same object -> returns true
assertTrue(receiptAliceCommand.equals(receiptAliceCommand));

// same values -> returns true
ReceiptCommand receiptAliceCommandCopy = new ReceiptCommand(INDEX_FIRST_PERSON);
assertTrue(receiptAliceCommand.equals(receiptAliceCommandCopy));

// different types -> returns false
assertFalse(receiptAliceCommand.equals(1));

// null -> returns false
assertFalse(receiptAliceCommand.equals(null));

// different patient -> returns false
assertFalse(receiptAliceCommand.equals(receiptBobCommand));
}
}
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));
}
}

0 comments on commit be95cff

Please sign in to comment.