diff --git a/src/test/java/seedu/address/model/patient/RecordTest.java b/src/test/java/seedu/address/model/patient/RecordTest.java new file mode 100644 index 00000000000..7d445bcda42 --- /dev/null +++ b/src/test/java/seedu/address/model/patient/RecordTest.java @@ -0,0 +1,98 @@ +package seedu.address.model.patient; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import seedu.address.testutil.RecordBuilder; + +public class RecordTest { + + @Test + public void addDepartment() { + Record record = new RecordBuilder().build(); + String newDepartment = "Neurology"; + record.addDepartment(newDepartment); + assertTrue(record.getDepartmentsVisited().contains(newDepartment)); + } + + @Test + public void getInitialObservations() { + String initialObservations = "Patient shows signs of fatigue."; + Record record = new RecordBuilder().withInitialObservations(initialObservations).build(); + assertEquals(initialObservations, record.getInitialObservations()); + } + + @Test + public void setInitialObservations() { + Record record = new RecordBuilder().build(); + String newInitialObservations = "Patient has a high fever."; + record.setInitialObservations(newInitialObservations); + assertEquals(newInitialObservations, record.getInitialObservations()); + } + + @Test + public void getDiagnosis() { + String diagnosis = "Migraine"; + Record record = new RecordBuilder().withDiagnosis(diagnosis).build(); + assertEquals(diagnosis, record.getDiagnosis()); + } + + @Test + public void setDiagnosis() { + Record record = new RecordBuilder().build(); + String newDiagnosis = "Flu"; + record.setDiagnosis(newDiagnosis); + assertEquals(newDiagnosis, record.getDiagnosis()); + } + + @Test + public void getTreatmentPlan() { + String treatmentPlan = "Paracetamol 500mg twice a day for a week."; + Record record = new RecordBuilder().withTreatmentPlan(treatmentPlan).build(); + assertEquals(treatmentPlan, record.getTreatmentPlan()); + } + + @Test + public void setTreatmentPlan() { + Record record = new RecordBuilder().build(); + String newTreatmentPlan = "Rest and drink plenty of fluids."; + record.setTreatmentPlan(newTreatmentPlan); + assertEquals(newTreatmentPlan, record.getTreatmentPlan()); + } + + @Test + public void equals() { + Record record1 = new RecordBuilder().build(); + Record record2 = new RecordBuilder().withInitialObservations("Different observation").build(); + + // same object -> returns true + assertTrue(record1.equals(record1)); + + // same values -> returns false + Record record1Copy = new RecordBuilder().build(); + assertFalse(record1.equals(record1Copy)); + + // null -> returns false + assertFalse(record1.equals(null)); + + // different type -> returns false + assertFalse(record1.equals(5)); + + // different record -> returns false + assertFalse(record1.equals(record2)); + } + + @Test + public void testToString() { + Record record = new RecordBuilder().build(); + String expected = Record.class.getCanonicalName() + "{patient=" + record.getPatient() + + ", departmentsVisited=" + record.getDepartmentsVisited() + + ", initialObservations=" + record.getInitialObservations() + + ", diagnosis=" + record.getDiagnosis() + + ", treatmentPlan=" + record.getTreatmentPlan() + "}"; + assertEquals(expected, record.toString()); + } +} diff --git a/src/test/java/seedu/address/testutil/RecordBuilder.java b/src/test/java/seedu/address/testutil/RecordBuilder.java new file mode 100644 index 00000000000..37f15087baa --- /dev/null +++ b/src/test/java/seedu/address/testutil/RecordBuilder.java @@ -0,0 +1,88 @@ +package seedu.address.testutil; + +import java.util.ArrayList; +import java.util.List; + +import seedu.address.model.patient.Patient; +import seedu.address.model.patient.Record; + +/** + * A utility class to help with building Record objects. + */ +public class RecordBuilder { + + private final Patient patient; + private List departmentsVisited; + private String initialObservations; + private String diagnosis; + private String treatmentPlan; + + /** + * Creates a {@code RecordBuilder} with the default details. + */ + public RecordBuilder() { + this.patient = new PatientBuilder().build(); // default patient + this.departmentsVisited = new ArrayList<>(); + this.initialObservations = ""; + this.diagnosis = ""; + this.treatmentPlan = ""; + } + + /** + * Initializes the RecordBuilder with the data of {@code recordToCopy}. + */ + public RecordBuilder(Record recordToCopy) { + this.patient = recordToCopy.getPatient(); + this.departmentsVisited = new ArrayList<>(recordToCopy.getDepartmentsVisited()); + this.initialObservations = recordToCopy.getInitialObservations(); + this.diagnosis = recordToCopy.getDiagnosis(); + this.treatmentPlan = recordToCopy.getTreatmentPlan(); + } + + /** + * Sets the {@code initialObservations} of the {@code Record} that we are building. + */ + public RecordBuilder withInitialObservations(String initialObservations) { + this.initialObservations = initialObservations; + return this; + } + + /** + * Sets the {@code diagnosis} of the {@code Record} that we are building. + */ + public RecordBuilder withDiagnosis(String diagnosis) { + this.diagnosis = diagnosis; + return this; + } + + /** + * Sets the {@code treatmentPlan} of the {@code Record} that we are building. + */ + public RecordBuilder withTreatmentPlan(String treatmentPlan) { + this.treatmentPlan = treatmentPlan; + return this; + } + + /** + * Adds a {@code department} to the {@code Record} that we are building. + */ + public RecordBuilder addDepartment(String department) { + this.departmentsVisited.add(department); + return this; + } + + /** + * Builds and returns the {@code Record} object. + */ + public Record build() { + Record record = new Record(patient); + for (String department : departmentsVisited) { + record.addDepartment(department); + } + record.setInitialObservations(initialObservations); + record.setDiagnosis(diagnosis); + record.setTreatmentPlan(treatmentPlan); + return record; + } + +}