Skip to content

Commit

Permalink
Fix existing appointment tests and add more appointment tests (#286)
Browse files Browse the repository at this point in the history
* Fix DeleteAppointmentCommand Tests

* Add tests for AppointmentContainsPatientPredicate

* Implement test for ListAppointmentCommand

Rename getTypicalAppointmentBook.

* Create test for JsonAdaptedAppointment

* Create test for JsonAppointmentBookStorage

* Generate typical appointments json data

* Create test for JsonSerializableAppointmentBook

* Fix test for AddAppointmentCommandParser

* Add clear prescriptions functionality before appointment book tests
  • Loading branch information
gycgabriel authored Nov 7, 2021
1 parent 3998c44 commit 2033ec4
Show file tree
Hide file tree
Showing 22 changed files with 496 additions and 159 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/docit/model/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public Set<Prescription> getPrescriptions() {
return prescriptions;
}

public void resetPrescriptions() {
prescriptions = new HashSet<>();
}

/**
* Adds a prescription into the appointment.
* @param prescription prescription to be added.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package seedu.docit.model.appointment;

import static java.util.Objects.requireNonNull;

import java.util.function.Predicate;

import seedu.docit.model.patient.Patient;


/**
* Tests that an {@code Appointment}'s {@code Patient} email matches any of the patient emails given.
* Tests that an {@code Appointment}'s {@code Patient} matches any of the patient given.
*/
public class AppointmentContainsPatientPredicate implements Predicate<Appointment> {
private final Patient patient;

/**
* Constructor for predicate that requires a non-null patient.
* @param patient patient object to test with
*/
public AppointmentContainsPatientPredicate(Patient patient) {
requireNonNull(patient);
this.patient = patient;
}

@Override
public boolean test(Appointment appointment) {
return patient.isSamePatient(appointment.getPatient());
if (appointment == null) {
return false;
} else {
return patient.isSamePatient(appointment.getPatient());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"appointments" : [ {
"datetime" : "2040-10-17 1200",
"prescriptionList" : [ ],
"patientIndex" : "0"
}, {
"datetime" : "20222-12 2000",
"prescriptionList" : [ ],
"patientIndex" : "a"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"appointments" : [ {
"datetime" : "20410-17 1200",
"prescriptionList" : [ ],
"patientIndex" : "0"
}, {
"datetime" : "2022-2as12 2000",
"prescriptionList" : [ ],
"patientIndex" : "0"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not json format!
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"appointments" : [ {
"datetime" : "2040-10-17 1200",
"prescriptionList" : [ ],
"patientIndex" : "0"
}, {
"datetime" : "2040-10-17 1200",
"prescriptionList" : [ ],
"patientIndex" : "0"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appointments" : [ {
"datetime" : "2022212 2000",
"prescriptionList" : [ ],
"patientIndex" : "a"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"appointments" : [ {
"datetime" : "2022-1-1 1600",
"prescriptionList" : [ ],
"patientIndex" : "0"
}, {
"datetime" : "2022-2-2 1600",
"prescriptionList" : [ ],
"patientIndex" : "0"
}, {
"datetime" : "2022-1-1 1600",
"prescriptionList" : [ ],
"patientIndex" : "1"
}, {
"datetime" : "2022-2-1 1600",
"prescriptionList" : [ ],
"patientIndex" : "1"
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

import seedu.docit.commons.core.index.Index;
import seedu.docit.model.Model;
import seedu.docit.model.appointment.Appointment;
import seedu.docit.model.appointment.AppointmentContainsPatientPredicate;
import seedu.docit.model.patient.Patient;

public class AppointmentCommandTestUtil {

/**
* Updates {@code model}'s filtered list to show appointments with patient at the given {@code targetIndex} in the
* {@code model}'s patient list.
* {@code model}'s patient list. May filter with more than one appointment.
*/
public static void showAppointmentWithPatientAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredAppointmentList().size());

Patient patient = model.getFilteredPatientList().get(targetIndex.getZeroBased());
model.updateFilteredAppointmentList(new AppointmentContainsPatientPredicate(patient));

assert(1 <= model.getFilteredAppointmentList().size());
}

/**
* Updates {@code model}'s filtered list to show appointment at the given {@code targetIndex}.
* Filters only one appointment.
*/
public static void showAppointmentAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredAppointmentList().size());

Appointment appointment = model.getFilteredAppointmentList().get(targetIndex.getZeroBased());
model.updateFilteredAppointmentList(x -> x.equals(appointment));

assertEquals(1, model.getFilteredAppointmentList().size());
}
}
17 changes: 9 additions & 8 deletions src/test/java/seedu/docit/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.docit.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_MEDICAL;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.docit.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -54,17 +55,17 @@ public class CommandTestUtil {
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final String VALID_PATIENT_ID_0 = "0";
public static final String VALID_PATIENT_ID_1 = "1";
public static final String VALID_PATIENT_ID_2 = "2";
public static final String VALID_PATIENT_INDEX_0 = "0";
public static final String VALID_PATIENT_INDEX_1 = "1";
public static final String VALID_PATIENT_INDEX_2 = "2";

public static final String VALID_PATIENT_ID_DESC_0 = " " + PREFIX_NAME + VALID_PATIENT_ID_0;
public static final String VALID_PATIENT_ID_DESC_1 = " " + PREFIX_NAME + VALID_PATIENT_ID_1;
public static final String VALID_PATIENT_ID_DESC_2 = " " + PREFIX_NAME + VALID_PATIENT_ID_2;
public static final String VALID_PATIENT_INDEX_DESC_0 = " " + PREFIX_INDEX + VALID_PATIENT_INDEX_0;
public static final String VALID_PATIENT_INDEX_DESC_1 = " " + PREFIX_INDEX + VALID_PATIENT_INDEX_1;
public static final String VALID_PATIENT_INDEX_DESC_2 = " " + PREFIX_INDEX + VALID_PATIENT_INDEX_2;

public static final String INVALID_PATIENT_ID_MINUS_1 = "-1";
public static final String INVALID_PATIENT_INDEX_MINUS_1 = "-1";

public static final String INVALID_PATIENT_ID_DESC_MINUS_1 = " " + PREFIX_NAME + INVALID_PATIENT_ID_MINUS_1;
public static final String INVALID_PATIENT_INDEX_DESC_MINUS_1 = " " + PREFIX_INDEX + INVALID_PATIENT_INDEX_MINUS_1;

public static final String VALID_APPOINTMENT_DATE_TIME = "2020-1-10 1600";
public static final String INVALID_APPOINTMENT_DATE_TIME_MONTH = "2020-13-10 1600"; // invalid month
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.docit.logic.commands.AppointmentCommandTestUtil.showAppointmentWithPatientAtIndex;
import static seedu.docit.logic.commands.AppointmentCommandTestUtil.showAppointmentAtIndex;
import static seedu.docit.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.docit.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentList;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentBook;
import static seedu.docit.testutil.TypicalIndexes.INDEX_FIRST_APPOINTMENT;
import static seedu.docit.testutil.TypicalIndexes.INDEX_FIRST_PATIENT;
import static seedu.docit.testutil.TypicalIndexes.INDEX_SECOND_APPOINTMENT;
Expand All @@ -24,7 +24,7 @@


public class DeleteAppointmentCommandTest {
private final Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentList(),
private final Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentBook(),
new AppointmentBook(), new UserPrefs());

@Test
Expand Down Expand Up @@ -52,7 +52,7 @@ public void execute_validIndexUnfilteredList_success() {

@Test
public void execute_validIndexFilteredList_success() {
showAppointmentWithPatientAtIndex(model, INDEX_FIRST_APPOINTMENT);
showAppointmentAtIndex(model, INDEX_FIRST_APPOINTMENT);

Appointment appointmentToDelete = model.getFilteredAppointmentList().get(
INDEX_FIRST_APPOINTMENT.getZeroBased());
Expand All @@ -71,7 +71,7 @@ public void execute_validIndexFilteredList_success() {

@Test
public void execute_invalidIndexFilteredList_throwsCommandException() {
showAppointmentWithPatientAtIndex(model, INDEX_FIRST_APPOINTMENT);
showAppointmentAtIndex(model, INDEX_FIRST_APPOINTMENT);

Index outOfBoundIndex = INDEX_SECOND_APPOINTMENT;
// ensures that outOfBoundIndex is still in bounds of address book list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package seedu.docit.logic.commands;

import static seedu.docit.logic.commands.AppointmentCommandTestUtil.showAppointmentWithPatientAtIndex;
import static seedu.docit.logic.commands.AppointmentCommandTestUtil.showAppointmentAtIndex;
import static seedu.docit.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentList;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentBook;
import static seedu.docit.testutil.TypicalIndexes.INDEX_FIRST_APPOINTMENT;
import static seedu.docit.testutil.TypicalPatients.getTypicalAddressBook;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import seedu.docit.model.AddressBook;
import seedu.docit.model.ArchivedAppointmentBook;
import seedu.docit.model.Model;
import seedu.docit.model.ModelManager;
import seedu.docit.model.UserPrefs;
Expand All @@ -25,23 +25,22 @@ public class ListAppointmentsCommandTest {

@BeforeEach
public void setUp() {
model = new ModelManager(new AddressBook(), getTypicalAppointmentList(),
getTypicalAppointmentList(), new UserPrefs());
expectedModel = new ModelManager(new AddressBook(), model.getAppointmentBook(),
model.getArchivedAppointmentBook(), new UserPrefs());
model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentBook(),
new ArchivedAppointmentBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), model.getAppointmentBook(),
new ArchivedAppointmentBook(), new UserPrefs());
}

@Test
@Disabled("Not implemented yet, currently list is shown in user feedback")
public void execute_listIsNotFiltered_showsSameList() {
assertCommandSuccess(new ListAppointmentsCommand(), model, ListAppointmentsCommand.MESSAGE_SUCCESS,
expectedModel);
}

@Test
@Disabled("Not implemented yet, currently list is shown in user feedback")
public void execute_listIsFiltered_showsEverything() {
showAppointmentWithPatientAtIndex(model, INDEX_FIRST_APPOINTMENT);
assertCommandSuccess(new ListPatientCommand(), model, ListAppointmentsCommand.MESSAGE_SUCCESS, expectedModel);
showAppointmentAtIndex(model, INDEX_FIRST_APPOINTMENT);
assertCommandSuccess(new ListAppointmentsCommand(), model,
ListAppointmentsCommand.MESSAGE_SUCCESS, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static seedu.docit.logic.commands.prescription.AddPrescriptionCommand.INPUT_TOO_LONG_ERROR_MESSAGE;
import static seedu.docit.logic.commands.prescription.AddPrescriptionCommand.MESSAGE_SUCCESS;
import static seedu.docit.testutil.Assert.assertThrows;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentList;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentBook;
import static seedu.docit.testutil.TypicalPatients.getTypicalAddressBook;

import java.util.Arrays;
Expand All @@ -31,7 +31,7 @@ public class AddPrescriptionCommandTest {
private static final Prescription validPrescription =
new Prescription(defaultMedicine, defaultVolume, defaultDuration);

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentList(),
private Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentBook(),
new ArchivedAppointmentBook(), new UserPrefs());
private final Appointment defaultAppointment = model.getAppointmentBook().getAppointmentList().get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.docit.commons.core.Messages.MESSAGE_INVALID_APPOINTMENT_DISPLAYED_INDEX;
import static seedu.docit.logic.commands.prescription.DeletePrescriptionCommand.MESSAGE_DELETE_PRESCRIPTION_SUCCESS;
import static seedu.docit.testutil.Assert.assertThrows;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentList;
import static seedu.docit.testutil.TypicalAppointments.getTypicalAppointmentBook;
import static seedu.docit.testutil.TypicalPatients.getTypicalAddressBook;

import org.junit.jupiter.api.Test;
Expand All @@ -30,7 +30,7 @@ public class DeletePrescriptionCommandTest {
private static final Prescription validPrescription =
new Prescription(defaultMedicine, defaultVolume, defaultDuration);

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentList(),
private Model model = new ModelManager(getTypicalAddressBook(), getTypicalAppointmentBook(),
new ArchivedAppointmentBook(), new UserPrefs());
private final Appointment defaultAppointment = model.getAppointmentBook().getAppointmentList().get(0);

Expand Down
Loading

0 comments on commit 2033ec4

Please sign in to comment.