-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentTest.java
More file actions
123 lines (101 loc) · 5.4 KB
/
Copy pathAppointmentTest.java
File metadata and controls
123 lines (101 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import org.junit.Test;
import static org.junit.Assert.*;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Comparator;
public class AppointmentTest {
@Test
public void testOnetimeAppointmentConstructor() {
OnetimeAppointment appointment = new OnetimeAppointment(LocalDate.of(2024, 11, 1), "customer appointment");
assertEquals(appointment.getStartDate(), appointment.getEndDate());
}
@Test
public void testOnetimeAppointmentOccursOn() {
OnetimeAppointment appointment = new OnetimeAppointment(LocalDate.of(2024, 11, 1), "customer appointment");
assertTrue(appointment.occursOn(LocalDate.of(2024, 11, 1)));
assertFalse(appointment.occursOn(LocalDate.of(2024, 11, 2)));
}
@Test
public void testDailyAppointmentOccursOn() {
DailyAppointment appointment = new DailyAppointment(LocalDate.of(2024, 11, 1), LocalDate.of(2024, 11, 5), "daily meetup");
assertTrue(appointment.occursOn(LocalDate.of(2024, 11, 3)));
assertFalse(appointment.occursOn(LocalDate.of(2024, 11, 6)));
}
@Test
public void testMonthlyAppointmentOccursOn() {
MonthlyAppointment appointment = new MonthlyAppointment(LocalDate.of(2024, 11, 1), LocalDate.of(2025, 1, 1), "monthly meetup");
assertTrue(appointment.occursOn(LocalDate.of(2024, 12, 1))); // Same day of month
assertFalse(appointment.occursOn(LocalDate.of(2024, 12, 2))); // Different day of month
}
@Test
public void testEqualsMethod() {
OnetimeAppointment appointment1 = new OnetimeAppointment(LocalDate.of(2024, 11, 1), "doctor schedule");
OnetimeAppointment appointment2 = new OnetimeAppointment(LocalDate.of(2024, 11, 1), "doctor schedule");
assertTrue(appointment1.equals(appointment2));
}
@Test
public void testCompareAppointments() {
OnetimeAppointment appointment1 = new OnetimeAppointment(LocalDate.of(2024, 11, 1), "doctor schedule");
DailyAppointment appointment2 = new DailyAppointment(LocalDate.of(2024, 11, 1), LocalDate.of(2024, 11, 5), "daily meetup");
Appointment[] appointments = {appointment2, appointment1};
Arrays.sort(appointments);
assertEquals(appointment1, appointments[0]); // ought to be arranged by the start date
}
// test AppointmentManager methods
@Test
public void testAddAppointment() {
AppointmentManager manager = new AppointmentManager();
OnetimeAppointment appointment = new OnetimeAppointment(LocalDate.of(2024, 12, 25), "customer appointment");
manager.add(appointment);
assertTrue(manager.getSortedAppointments().contains(appointment));
}
@Test
public void testAddDuplicateAppointment() {
AppointmentManager manager = new AppointmentManager();
OnetimeAppointment appointment = new OnetimeAppointment(LocalDate.of(2024, 12, 25), "customer appointment");
manager.add(appointment);
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
manager.add(appointment); // Adding duplicate
});
assertEquals("Appointment exists!", exception.getMessage()); // Fixed message
}
@Test
public void testDeleteAppointment() {
AppointmentManager manager = new AppointmentManager();
OnetimeAppointment appointment = new OnetimeAppointment(LocalDate.of(2024, 12, 25), "customer appointment");
manager.add(appointment);
manager.delete(appointment);
assertFalse(manager.getSortedAppointments().contains(appointment));
}
@Test
public void testUpdateAppointment() {
AppointmentManager manager = new AppointmentManager();
OnetimeAppointment oldAppointment = new OnetimeAppointment(LocalDate.of(2024, 12, 25), "customer appointment");
OnetimeAppointment newAppointment = new OnetimeAppointment(LocalDate.of(2024, 12, 31), "updated customer appointment");
manager.add(oldAppointment);
manager.update(oldAppointment, newAppointment);
assertFalse(manager.getSortedAppointments().contains(oldAppointment));
assertTrue(manager.getSortedAppointments().contains(newAppointment));
}
@Test
public void testGetAppointmentsOn() {
AppointmentManager manager = new AppointmentManager();
DailyAppointment appointment1 = new DailyAppointment(LocalDate.of(2024, 11, 1), LocalDate.of(2024, 11, 5), "daily meetup");
OnetimeAppointment appointment2 = new OnetimeAppointment(LocalDate.of(2024, 11, 3), "customer appointment");
manager.add(appointment1);
manager.add(appointment2);
Appointment[] results = manager.getAppointmentsOn(LocalDate.of(2024, 11, 3), null);
assertEquals(2, results.length);
}
@Test
public void testGetAppointmentsSorted() {
AppointmentManager manager = new AppointmentManager();
OnetimeAppointment appointment1 = new OnetimeAppointment(LocalDate.of(2024, 12, 25), "customer appointment");
OnetimeAppointment appointment2 = new OnetimeAppointment(LocalDate.of(2024, 12, 31), "updated customer appointment");
manager.add(appointment1);
manager.add(appointment2);
Appointment[] results = manager.getAppointmentsOn(null, Comparator.comparing(Appointment::getDescription));
assertEquals("customer appointment", results[0].getDescription());
assertEquals("updated customer appointment", results[1].getDescription());
}
}