forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for UniqueAppointmentList, UniqueDoctorList, UniquePat…
…ientList
- Loading branch information
1 parent
0bf21f4
commit 9fc8882
Showing
3 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
src/test/java/seedu/address/model/person/UniqueAppointmentListTest.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,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<Appointment>) null)); | ||
} | ||
|
||
@Test | ||
public void setObjects_list_replacesOwnListWithProvidedList() { | ||
UniqueAppointmentList.add(APPOINTMENT_1); | ||
List<Appointment> 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<Appointment> 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()); | ||
} | ||
} | ||
|
176 changes: 176 additions & 0 deletions
176
src/test/java/seedu/address/model/person/UniqueDoctorListTest.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,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<Doctor>) null)); | ||
} | ||
|
||
@Test | ||
public void setObjects_list_replacesOwnListWithProvidedList() { | ||
UniqueDoctorList.add(ALICE); | ||
List<Doctor> DoctorList = Collections.singletonList(BOYD); | ||
UniqueDoctorList.setObjects(DoctorList); | ||
UniqueDoctorList expectedUniqueDoctorList = new UniqueDoctorList(); | ||
expectedUniqueDoctorList.add(BOYD); | ||
assertEquals(expectedUniqueDoctorList, UniqueDoctorList); | ||
} | ||
|
||
@Test | ||
public void setObjects_listWithDuplicatePersons_throwsDuplicatePersonException() { | ||
List<Doctor> 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()); | ||
} | ||
} |
Oops, something went wrong.