|
1 | 1 | package seedu.address.model.appointment; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 7 | + |
| 8 | +import java.time.LocalDate; |
| 9 | + |
3 | 10 | import org.junit.jupiter.api.Test; |
4 | 11 |
|
| 12 | +import seedu.address.model.person.Nric; |
| 13 | +import seedu.address.model.person.Person; |
| 14 | +import seedu.address.testutil.DoctorBuilder; |
| 15 | +import seedu.address.testutil.PatientBuilder; |
| 16 | + |
5 | 17 | class AppointmentTest { |
6 | 18 |
|
7 | 19 | @Test |
8 | | - void getDoctoNric() { |
| 20 | + void getDoctorNric() { |
| 21 | + Nric doctorNric = new Nric("S1234567A"); |
| 22 | + Appointment appointment = new Appointment(doctorNric, new Nric("T1234567A"), |
| 23 | + new AppointmentDate(LocalDate.now())); |
| 24 | + assertEquals(doctorNric, appointment.getDoctorNric()); |
9 | 25 | } |
10 | 26 |
|
11 | 27 | @Test |
12 | 28 | void getPatientNric() { |
| 29 | + Nric patientNric = new Nric("T1234567A"); |
| 30 | + Appointment appointment = new Appointment(new Nric("S1234567A"), patientNric, |
| 31 | + new AppointmentDate(LocalDate.now())); |
| 32 | + assertEquals(patientNric, appointment.getPatientNric()); |
13 | 33 | } |
14 | 34 |
|
15 | 35 | @Test |
16 | 36 | void getAppointmentId() { |
| 37 | + AppointmentId appointmentId = new AppointmentId(); |
| 38 | + Appointment appointment = new Appointment(new Nric("S1234567A"), new Nric("T1234567A"), |
| 39 | + new AppointmentDate(LocalDate.now()), appointmentId); |
| 40 | + assertEquals(appointmentId, appointment.getAppointmentId()); |
17 | 41 | } |
18 | 42 |
|
19 | 43 | @Test |
20 | 44 | void getAppointmentDate() { |
| 45 | + AppointmentDate appointmentDate = new AppointmentDate(LocalDate.now()); |
| 46 | + Appointment appointment = new Appointment(new Nric("S1234567A"), new Nric("T1234567A"), appointmentDate); |
| 47 | + assertEquals(appointmentDate, appointment.getAppointmentDate()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void isValidAppointment_validDate_returnsTrue() { |
| 52 | + AppointmentDate futureDate = new AppointmentDate(LocalDate.now().plusDays(1)); |
| 53 | + Appointment appointment = new Appointment(new Nric("S1234567A"), new Nric("T1234567A"), futureDate); |
| 54 | + |
| 55 | + assertTrue(appointment.isValidAppointment(futureDate)); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void isValidAppointment_pastDate_returnsFalse() { |
| 60 | + AppointmentDate pastDate = new AppointmentDate(LocalDate.now().minusDays(1)); |
| 61 | + // Use assertThrows to check if IllegalArgumentException is thrown |
| 62 | + assertThrows(IllegalArgumentException.class, () -> { |
| 63 | + new Appointment(new Nric("S1234567A"), new Nric("T1234567A"), pastDate); |
| 64 | + }); |
21 | 65 | } |
22 | 66 |
|
23 | 67 | @Test |
24 | 68 | void isSameAppointment() { |
| 69 | + Nric doctorNric = new Nric("S1234567A"); |
| 70 | + Nric patientNric = new Nric("T1234567A"); |
| 71 | + AppointmentDate appointmentDate = new AppointmentDate(LocalDate.now()); |
| 72 | + Appointment appointment1 = new Appointment(doctorNric, patientNric, appointmentDate); |
| 73 | + Appointment appointment2 = new Appointment(doctorNric, patientNric, appointmentDate); |
| 74 | + assertTrue(appointment1.isSameAppointment(appointment2)); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void appointmentContainsPerson() { |
| 79 | + Nric doctorNric = new Nric("S1234567A"); |
| 80 | + Nric patientNric = new Nric("T1234567A"); |
| 81 | + AppointmentDate appointmentDate = new AppointmentDate(LocalDate.now()); |
| 82 | + Appointment appointment = new Appointment(doctorNric, patientNric, appointmentDate); |
| 83 | + |
| 84 | + // False Doctor and Patient |
| 85 | + Person doctor = new DoctorBuilder().withNric("S7654321A").build(); |
| 86 | + Person patient = new PatientBuilder().withNric("T7654321A").build(); |
| 87 | + assertFalse(appointment.appointmentContainsPerson(doctor)); |
| 88 | + assertFalse(appointment.appointmentContainsPerson(patient)); |
| 89 | + |
| 90 | + // True Doctor and Patient |
| 91 | + doctor = new DoctorBuilder().withNric("S1234567A").build(); |
| 92 | + patient = new PatientBuilder().withNric("T1234567A").build(); |
| 93 | + assertTrue(appointment.appointmentContainsPerson(doctor)); |
| 94 | + assertTrue(appointment.appointmentContainsPerson(patient)); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + void testEquals() { |
| 99 | + Nric doctorNric = new Nric("S1234567A"); |
| 100 | + Nric patientNric = new Nric("T1234567A"); |
| 101 | + AppointmentDate appointmentDate = new AppointmentDate(LocalDate.now()); |
| 102 | + Appointment appointment1 = new Appointment(doctorNric, patientNric, appointmentDate); |
| 103 | + Appointment appointment2 = new Appointment(doctorNric, patientNric, appointmentDate); |
| 104 | + assertEquals(appointment1, appointment2); |
25 | 105 | } |
26 | 106 |
|
27 | 107 | @Test |
28 | 108 | void testToString() { |
| 109 | + Nric doctorNric = new Nric("S1234567A"); |
| 110 | + Nric patientNric = new Nric("T1234567A"); |
| 111 | + AppointmentDate appointmentDate = new AppointmentDate(LocalDate.now()); |
| 112 | + AppointmentId appointmentId = new AppointmentId(); |
| 113 | + Appointment appointment = new Appointment(doctorNric, patientNric, appointmentDate, appointmentId); |
| 114 | + String expectedString = "seedu.address.model.appointment.Appointment{Date=" + appointmentDate + ", Doctor=" |
| 115 | + + doctorNric + ", Patient=" + patientNric + ", Id=" + appointmentId + "}"; |
| 116 | + assertEquals(expectedString, appointment.toString()); |
29 | 117 | } |
30 | 118 | } |
0 commit comments