From 9fc88826bbacb667338a4e138e15e773f97194cf Mon Sep 17 00:00:00 2001 From: chonguschonguschongus Date: Wed, 8 Nov 2023 20:52:55 +0800 Subject: [PATCH] Add test cases for UniqueAppointmentList, UniqueDoctorList, UniquePatientList --- .../person/UniqueAppointmentListTest.java | 141 ++++++++++++++ .../model/person/UniqueDoctorListTest.java | 176 ++++++++++++++++++ .../model/person/UniquePatientListTest.java | 174 +++++++++++++++++ 3 files changed, 491 insertions(+) create mode 100644 src/test/java/seedu/address/model/person/UniqueAppointmentListTest.java create mode 100644 src/test/java/seedu/address/model/person/UniqueDoctorListTest.java create mode 100644 src/test/java/seedu/address/model/person/UniquePatientListTest.java diff --git a/src/test/java/seedu/address/model/person/UniqueAppointmentListTest.java b/src/test/java/seedu/address/model/person/UniqueAppointmentListTest.java new file mode 100644 index 00000000000..fd10c76cbdc --- /dev/null +++ b/src/test/java/seedu/address/model/person/UniqueAppointmentListTest.java @@ -0,0 +1,141 @@ +package seedu.address.model.person; + +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 static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalAppointment.APPOINTMENT_1; +import static seedu.address.testutil.TypicalAppointment.APPOINTMENT_2; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.appointment.Appointment; +import seedu.address.model.person.exceptions.DuplicateObjectException; +import seedu.address.model.person.exceptions.ObjectNotFoundException; + +public class UniqueAppointmentListTest { + + private final UniqueAppointmentList UniqueAppointmentList = new UniqueAppointmentList(); + + @Test + public void contains_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.contains(null)); + } + + @Test + public void contains_personNotInList_returnsFalse() { + assertFalse(UniqueAppointmentList.contains(APPOINTMENT_1)); + } + + @Test + public void contains_personInList_returnsTrue() { + UniqueAppointmentList.add(APPOINTMENT_1); + assertTrue(UniqueAppointmentList.contains(APPOINTMENT_1)); + } + + @Test + public void add_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.add(null)); + } + + @Test + public void add_duplicatePerson_throwsDuplicateAppointmentException() { + UniqueAppointmentList.add(APPOINTMENT_1); + assertThrows(DuplicateObjectException.class, () -> UniqueAppointmentList.add(APPOINTMENT_1)); + } + + @Test + public void setObject_nullTargetAppointment_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.setObject(null, APPOINTMENT_2)); + } + + @Test + public void setObject_nullEditedAppointment_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.setObject(APPOINTMENT_1, + null)); + } + + @Test + public void setObject_targetPersonNotInList_throwsObjectNotFoundException() { + assertThrows(ObjectNotFoundException.class, () -> UniqueAppointmentList.setObject(APPOINTMENT_1, + APPOINTMENT_1)); + } + + @Test + public void setObject_editedPersonIsSamePerson_success() { + UniqueAppointmentList.add(APPOINTMENT_1); + UniqueAppointmentList.setObject(APPOINTMENT_1, APPOINTMENT_1); + UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList(); + expectedUniqueAppointmentList.add(APPOINTMENT_1); + assertEquals(expectedUniqueAppointmentList, UniqueAppointmentList); + } + + @Test + public void remove_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.remove(null)); + } + + @Test + public void remove_personDoesNotExist_throwsObjectNotFoundException() { + assertThrows(ObjectNotFoundException.class, () -> UniqueAppointmentList.remove(APPOINTMENT_1)); + } + + @Test + public void remove_existingPerson_removesPerson() { + UniqueAppointmentList.add(APPOINTMENT_1); + UniqueAppointmentList.remove(APPOINTMENT_1); + UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList(); + assertEquals(expectedUniqueAppointmentList, UniqueAppointmentList); + } + + @Test + public void setPersons_nullUniqueAppointmentList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.setAppointments((UniqueAppointmentList) null)); + } + + @Test + public void setObjects_UniqueAppointmentList_replacesOwnListWithProvidedUniqueAppointmentList() { + UniqueAppointmentList.add(APPOINTMENT_1); + UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList(); + expectedUniqueAppointmentList.add(APPOINTMENT_2); + UniqueAppointmentList.setAppointments(expectedUniqueAppointmentList); + assertEquals(expectedUniqueAppointmentList, UniqueAppointmentList); + } + + @Test + public void setPersons_nullList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueAppointmentList.setObjects((List) null)); + } + + @Test + public void setObjects_list_replacesOwnListWithProvidedList() { + UniqueAppointmentList.add(APPOINTMENT_1); + List AppointmentList = Collections.singletonList(APPOINTMENT_1); + UniqueAppointmentList.setObjects(AppointmentList); + UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList(); + expectedUniqueAppointmentList.add(APPOINTMENT_1); + assertEquals(expectedUniqueAppointmentList, UniqueAppointmentList); + } + + @Test + public void setObjects_listWithDuplicatePersons_throwsDuplicateObjectException() { + List listWithDuplicateAppointments = Arrays.asList(APPOINTMENT_1, APPOINTMENT_1); + assertThrows(DuplicateObjectException.class, () -> UniqueAppointmentList.setObjects(listWithDuplicateAppointments)); + } + + @Test + public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () + -> UniqueAppointmentList.asUnmodifiableObservableList().remove(0)); + } + + @Test + public void toStringMethod() { + assertEquals(UniqueAppointmentList.asUnmodifiableObservableList().toString(), UniqueAppointmentList.toString()); + } +} + diff --git a/src/test/java/seedu/address/model/person/UniqueDoctorListTest.java b/src/test/java/seedu/address/model/person/UniqueDoctorListTest.java new file mode 100644 index 00000000000..855c93c9de4 --- /dev/null +++ b/src/test/java/seedu/address/model/person/UniqueDoctorListTest.java @@ -0,0 +1,176 @@ +package seedu.address.model.person; + +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 static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_DEREK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_CARDIOLOGIST; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MEDIUM; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalDoctor.ALICE; +import static seedu.address.testutil.TypicalDoctor.BOYD; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.person.exceptions.DuplicatePersonException; +import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.testutil.DoctorBuilder; + +public class UniqueDoctorListTest { + + private final UniqueDoctorList UniqueDoctorList = new UniqueDoctorList(); + + @Test + public void contains_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.contains(null)); + } + + @Test + public void contains_personNotInList_returnsFalse() { + assertFalse(UniqueDoctorList.contains(ALICE)); + } + + @Test + public void contains_personInList_returnsTrue() { + UniqueDoctorList.add(ALICE); + assertTrue(UniqueDoctorList.contains(ALICE)); + } + + @Test + public void contains_personWithSameIdentityFieldsInList_returnsTrue() { + UniqueDoctorList.add(ALICE); + Doctor editedALICE = new DoctorBuilder(ALICE).withAddress(VALID_ADDRESS_DEREK).withTags(VALID_TAG_CARDIOLOGIST) + .build(); + assertTrue(UniqueDoctorList.contains(editedALICE)); + } + + @Test + public void add_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.add(null)); + } + + @Test + public void add_duplicatePerson_throwsDuplicatePersonException() { + UniqueDoctorList.add(ALICE); + assertThrows(DuplicatePersonException.class, () -> UniqueDoctorList.add(ALICE)); + } + + @Test + public void setObject_nullTargetPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.setObject(null, ALICE)); + } + + @Test + public void setObject_nullEditedPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.setObject(ALICE, null)); + } + + @Test + public void setObject_targetPersonNotInList_throwsPersonNotFoundException() { + assertThrows(PersonNotFoundException.class, () -> UniqueDoctorList.setObject(ALICE, ALICE)); + } + + @Test + public void setObject_editedPersonIsSamePerson_success() { + UniqueDoctorList.add(ALICE); + UniqueDoctorList.setObject(ALICE, ALICE); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + expectedUniqueDoctorList.add(ALICE); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setObject_editedPersonHasSameIdentity_success() { + UniqueDoctorList.add(ALICE); + Doctor editedALICE = new DoctorBuilder(ALICE).withAddress(VALID_ADDRESS_DEREK).withTags(VALID_TAG_MEDIUM) + .build(); + UniqueDoctorList.setObject(ALICE, editedALICE); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + expectedUniqueDoctorList.add(editedALICE); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setObject_editedPersonHasDifferentIdentity_success() { + UniqueDoctorList.add(ALICE); + UniqueDoctorList.setObject(ALICE, BOYD); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + expectedUniqueDoctorList.add(BOYD); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setObject_editedPersonHasNonUniqueIdentity_throwsDuplicatePersonException() { + UniqueDoctorList.add(ALICE); + UniqueDoctorList.add(BOYD); + assertThrows(DuplicatePersonException.class, () -> UniqueDoctorList.setObject(ALICE, BOYD)); + } + + @Test + public void remove_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.remove(null)); + } + + @Test + public void remove_personDoesNotExist_throwsPersonNotFoundException() { + assertThrows(PersonNotFoundException.class, () -> UniqueDoctorList.remove(ALICE)); + } + + @Test + public void remove_existingPerson_removesPerson() { + UniqueDoctorList.add(ALICE); + UniqueDoctorList.remove(ALICE); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setPersons_nullUniqueDoctorList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.setDoctors((UniqueDoctorList) null)); + } + + @Test + public void setPersons_UniqueDoctorList_replacesOwnListWithProvidedUniqueDoctorList() { + UniqueDoctorList.add(ALICE); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + expectedUniqueDoctorList.add(BOYD); + UniqueDoctorList.setDoctors(expectedUniqueDoctorList); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setPersons_nullList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniqueDoctorList.setObjects((List) null)); + } + + @Test + public void setObjects_list_replacesOwnListWithProvidedList() { + UniqueDoctorList.add(ALICE); + List DoctorList = Collections.singletonList(BOYD); + UniqueDoctorList.setObjects(DoctorList); + UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); + expectedUniqueDoctorList.add(BOYD); + assertEquals(expectedUniqueDoctorList, UniqueDoctorList); + } + + @Test + public void setObjects_listWithDuplicatePersons_throwsDuplicatePersonException() { + List listWithDuplicateDoctors = Arrays.asList(ALICE, ALICE); + assertThrows(DuplicatePersonException.class, () -> UniqueDoctorList.setObjects(listWithDuplicateDoctors)); + } + + @Test + public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () + -> UniqueDoctorList.asUnmodifiableObservableList().remove(0)); + } + + @Test + public void toStringMethod() { + assertEquals(UniqueDoctorList.asUnmodifiableObservableList().toString(), UniqueDoctorList.toString()); + } +} diff --git a/src/test/java/seedu/address/model/person/UniquePatientListTest.java b/src/test/java/seedu/address/model/person/UniquePatientListTest.java new file mode 100644 index 00000000000..b2a3068cdf2 --- /dev/null +++ b/src/test/java/seedu/address/model/person/UniquePatientListTest.java @@ -0,0 +1,174 @@ +package seedu.address.model.person; + +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 static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MEDIUM; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalPatient.AMY; +import static seedu.address.testutil.TypicalPatient.BOB; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.person.exceptions.DuplicatePersonException; +import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.testutil.PatientBuilder; + +public class UniquePatientListTest { + + private final UniquePatientList UniquePatientList = new UniquePatientList(); + + @Test + public void contains_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.contains(null)); + } + + @Test + public void contains_personNotInList_returnsFalse() { + assertFalse(UniquePatientList.contains(AMY)); + } + + @Test + public void contains_personInList_returnsTrue() { + UniquePatientList.add(AMY); + assertTrue(UniquePatientList.contains(AMY)); + } + + @Test + public void contains_personWithSameIdentityFieldsInList_returnsTrue() { + UniquePatientList.add(AMY); + Patient editedAMY = new PatientBuilder(AMY).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_MEDIUM).build(); + assertTrue(UniquePatientList.contains(editedAMY)); + } + + @Test + public void add_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.add(null)); + } + + @Test + public void add_duplicatePerson_throwsDuplicatePersonException() { + UniquePatientList.add(AMY); + assertThrows(DuplicatePersonException.class, () -> UniquePatientList.add(AMY)); + } + + @Test + public void setObject_nullTargetPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.setObject(null, AMY)); + } + + @Test + public void setObject_nullEditedPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.setObject(AMY, null)); + } + + @Test + public void setObject_targetPersonNotInList_throwsPersonNotFoundException() { + assertThrows(PersonNotFoundException.class, () -> UniquePatientList.setObject(AMY, AMY)); + } + + @Test + public void setObject_editedPersonIsSamePerson_success() { + UniquePatientList.add(AMY); + UniquePatientList.setObject(AMY, AMY); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + expectedUniquePatientList.add(AMY); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setObject_editedPersonHasSameIdentity_success() { + UniquePatientList.add(AMY); + Patient editedAMY = new PatientBuilder(AMY).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_MEDIUM) + .build(); + UniquePatientList.setObject(AMY, editedAMY); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + expectedUniquePatientList.add(editedAMY); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setObject_editedPersonHasDifferentIdentity_success() { + UniquePatientList.add(AMY); + UniquePatientList.setObject(AMY, BOB); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + expectedUniquePatientList.add(BOB); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setObject_editedPersonHasNonUniqueIdentity_throwsDuplicatePersonException() { + UniquePatientList.add(AMY); + UniquePatientList.add(BOB); + assertThrows(DuplicatePersonException.class, () -> UniquePatientList.setObject(AMY, BOB)); + } + + @Test + public void remove_nullPerson_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.remove(null)); + } + + @Test + public void remove_personDoesNotExist_throwsPersonNotFoundException() { + assertThrows(PersonNotFoundException.class, () -> UniquePatientList.remove(AMY)); + } + + @Test + public void remove_existingPerson_removesPerson() { + UniquePatientList.add(AMY); + UniquePatientList.remove(AMY); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setPersons_nullUniquePatientList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.setPersons((UniquePatientList) null)); + } + + @Test + public void setPersons_UniquePatientList_replacesOwnListWithProvidedUniquePatientList() { + UniquePatientList.add(AMY); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + expectedUniquePatientList.add(BOB); + UniquePatientList.setPersons(expectedUniquePatientList); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setPersons_nullList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> UniquePatientList.setObjects((List) null)); + } + + @Test + public void setObjects_list_replacesOwnListWithProvidedList() { + UniquePatientList.add(AMY); + List patientList = Collections.singletonList(BOB); + UniquePatientList.setObjects(patientList); + UniquePatientList expectedUniquePatientList = new UniquePatientList(); + expectedUniquePatientList.add(BOB); + assertEquals(expectedUniquePatientList, UniquePatientList); + } + + @Test + public void setObjects_listWithDuplicatePersons_throwsDuplicatePersonException() { + List listWithDuplicatePatients = Arrays.asList(AMY, AMY); + assertThrows(DuplicatePersonException.class, () -> UniquePatientList.setObjects(listWithDuplicatePatients)); + } + + @Test + public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () + -> UniquePatientList.asUnmodifiableObservableList().remove(0)); + } + + @Test + public void toStringMethod() { + assertEquals(UniquePatientList.asUnmodifiableObservableList().toString(), UniquePatientList.toString()); + } +}