|
1 | 1 | package com.capgemini.training.appointmentbooking.dataaccess.repository; |
2 | 2 |
|
3 | | -import com.capgemini.training.appointmentbooking.common.BaseDataJpaTest; |
| 3 | +import com.capgemini.training.appointmentbooking.dataaccess.common.BaseDataJpaTest; |
4 | 4 | import com.capgemini.training.appointmentbooking.common.datatype.AppointmentStatus; |
5 | 5 | import com.capgemini.training.appointmentbooking.dataaccess.entity.AppointmentEntity; |
6 | 6 | import com.capgemini.training.appointmentbooking.dataaccess.entity.ClientEntity; |
|
14 | 14 | import java.util.List; |
15 | 15 | import java.util.Optional; |
16 | 16 |
|
17 | | -public class AppointmentRepositoryIT extends BaseDataJpaTest { |
| 17 | +class AppointmentRepositoryIT extends BaseDataJpaTest { |
18 | 18 |
|
19 | 19 | @Inject |
20 | 20 | private AppointmentRepository appointmentRepository; |
@@ -161,79 +161,74 @@ void shouldFindAppointmentsBySpecialistIdBeforeDate() { |
161 | 161 | .allMatch(a -> a.getDateTime().isBefore(date), "All appointments should be before the given date"); |
162 | 162 | } |
163 | 163 |
|
| 164 | + /** |
| 165 | + * Given a saved appointment from 11:45 to 12:00, |
| 166 | + * this test ensures that an earlier appointment does not trigger a conflict. |
| 167 | + */ |
164 | 168 | @Test |
165 | | - void shouldNotFindConflictedAppointmentBefore() { |
166 | | - // given |
| 169 | + void shouldNotFindConflictingAppointmentWhenNewAppointmentEndsBeforeExisting() { |
167 | 170 | Long specialistId = -1L; |
168 | | - Instant date = toInstant("2024-03-05 11:30:00"); |
| 171 | + Instant startDate = toInstant("2024-03-05 11:30:00"); |
169 | 172 | Instant endDate = toInstant("2024-03-05 11:45:00"); |
170 | 173 |
|
171 | | - // when |
172 | | - boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, date, |
173 | | - endDate); |
| 174 | + boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, startDate, endDate); |
174 | 175 |
|
175 | | - // then |
176 | 176 | assertThat(conflict).isFalse(); |
177 | 177 | } |
178 | 178 |
|
| 179 | + /** |
| 180 | + * Ensures that an appointment starting after an existing one does not conflict. |
| 181 | + */ |
179 | 182 | @Test |
180 | | - void shouldNotFindConflictedAppointmentAfter() { |
181 | | - // given |
| 183 | + void shouldNotFindConflictingAppointmentWhenNewAppointmentStartsAfterExisting() { |
182 | 184 | Long specialistId = -1L; |
183 | | - Instant date = toInstant("2024-03-05 12:00:00"); |
| 185 | + Instant startDate = toInstant("2024-03-05 12:00:00"); |
184 | 186 | Instant endDate = toInstant("2024-03-05 12:01:00"); |
185 | 187 |
|
186 | | - // when |
187 | | - boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, date, |
188 | | - endDate); |
| 188 | + boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, startDate, endDate); |
189 | 189 |
|
190 | | - // then |
191 | 190 | assertThat(conflict).isFalse(); |
192 | 191 | } |
193 | 192 |
|
| 193 | + /** |
| 194 | + * Verifies that an appointment starting and ending at exactly the same time as an existing one is treated as a conflict. |
| 195 | + */ |
194 | 196 | @Test |
195 | | - void shouldFindConflictedAppointmentExact() { |
196 | | - // given |
| 197 | + void shouldFindConflictingAppointmentWhenTimeMatchesExactly() { |
197 | 198 | Long specialistId = -1L; |
198 | | - Instant date = toInstant("2024-03-05 11:45:00"); |
| 199 | + Instant startDate = toInstant("2024-03-05 11:45:00"); |
199 | 200 | Instant endDate = toInstant("2024-03-05 12:00:00"); |
200 | 201 |
|
201 | | - // when |
202 | | - boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, date, |
203 | | - endDate); |
| 202 | + boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, startDate, endDate); |
204 | 203 |
|
205 | | - // then |
206 | 204 | assertThat(conflict).isTrue(); |
207 | 205 | } |
208 | 206 |
|
| 207 | + /** |
| 208 | + * Ensures that an appointment which starts before and ends during the existing one is considered a conflict. |
| 209 | + */ |
209 | 210 | @Test |
210 | | - void shouldFindConflictedAppointmentBegin() { |
211 | | - // given |
| 211 | + void shouldFindConflictingAppointmentWhenEndingOverlapsWithExisting() { |
212 | 212 | Long specialistId = -1L; |
213 | | - Instant date = toInstant("2024-03-05 11:40:00"); |
| 213 | + Instant startDate = toInstant("2024-03-05 11:40:00"); |
214 | 214 | Instant endDate = toInstant("2024-03-05 11:45:01"); |
215 | 215 |
|
216 | | - // when |
217 | | - boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, date, |
218 | | - endDate); |
| 216 | + boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, startDate, endDate); |
219 | 217 |
|
220 | | - // then |
221 | 218 | assertThat(conflict).isTrue(); |
222 | 219 | } |
223 | 220 |
|
| 221 | + /** |
| 222 | + * Checks that an appointment starting just before the end of an existing one is correctly flagged as a conflict. |
| 223 | + */ |
224 | 224 | @Test |
225 | | - void shouldFindConflictedAppointmentEnd() { |
226 | | - // given |
| 225 | + void shouldFindConflictingAppointmentWhenStartingBeforeExistingEnds() { |
227 | 226 | Long specialistId = -1L; |
228 | | - Instant date = toInstant("2024-03-05 11:59:59"); |
| 227 | + Instant startDate = toInstant("2024-03-05 11:59:59"); |
229 | 228 | Instant endDate = toInstant("2024-03-05 12:05:00"); |
230 | 229 |
|
231 | | - // when |
232 | | - boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, date, |
233 | | - endDate); |
| 230 | + boolean conflict = appointmentRepository.hasConflictingAppointmentBySpecialistIdAndDateTime(specialistId, startDate, endDate); |
234 | 231 |
|
235 | | - // then |
236 | 232 | assertThat(conflict).isTrue(); |
237 | 233 | } |
238 | | - |
239 | 234 | } |
0 commit comments