diff --git a/src/test/java/com/SleepUp/SU/utils/EmailServiceHelperTest.java b/src/test/java/com/SleepUp/SU/utils/EmailServiceHelperTest.java index f37d8b3..5256dc6 100644 --- a/src/test/java/com/SleepUp/SU/utils/EmailServiceHelperTest.java +++ b/src/test/java/com/SleepUp/SU/utils/EmailServiceHelperTest.java @@ -88,7 +88,7 @@ void validateEmailConfig_missingFields_shouldDisableEmail() { @Nested class SendWelcomeEmailGroup { @Test - void sendWelcomeEmail_Success() throws MessagingException { + void sendWelcomeEmail_serviceCallSuccess_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendWelcomeEmail(any(User.class)); emailServiceHelper.sendWelcomeEmail(guest); @@ -97,7 +97,7 @@ void sendWelcomeEmail_Success() throws MessagingException { } @Test - void sendWelcomeEmail_HandlesException() throws MessagingException { + void sendWelcomeEmail_serviceThrowsException_shouldHandleGracefullyAndNotThrow() throws MessagingException { doThrow(new MessagingException("Error")).when(emailService).sendWelcomeEmail(any(User.class)); assertDoesNotThrow(() -> emailServiceHelper.sendWelcomeEmail(guest)); @@ -110,7 +110,7 @@ void sendWelcomeEmail_HandlesException() throws MessagingException { @Nested class SendOwnerReservedNotificationGroup { @Test - void sendOwnerReservedNotification_Success() throws MessagingException { + void sendOwnerReservedNotification_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendOwnerReservedNotification(any(Reservation.class)); emailServiceHelper.sendOwnerReservedNotification(reservation); @@ -122,7 +122,7 @@ void sendOwnerReservedNotification_Success() throws MessagingException { @Nested class SendReservationConfirmationEmailGroup { @Test - void sendReservationConfirmationEmail_Success() throws MessagingException { + void sendReservationConfirmationEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendGuestReservationConfirmationEmail(any(Reservation.class), any(BigDecimal.class)); emailServiceHelper.sendReservationConfirmationEmail(reservation, BigDecimal.TEN); @@ -134,7 +134,7 @@ void sendReservationConfirmationEmail_Success() throws MessagingException { @Nested class SendReservationReminderEmailGroup { @Test - void sendReservationReminderEmail_Success() throws MessagingException { + void sendReservationReminderEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendGuestReservationReminderEmail(any(Reservation.class)); emailServiceHelper.sendReservationReminderEmail(reservation); @@ -146,7 +146,7 @@ void sendReservationReminderEmail_Success() throws MessagingException { @Nested class SendOwnerReservationReminderEmailGroup { @Test - void sendOwnerReservationReminderEmail_Success() throws MessagingException { + void sendOwnerReservationReminderEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendOwnerReservationReminderEmail(any(Reservation.class)); emailServiceHelper.sendOwnerReservationReminderEmail(reservation); @@ -158,7 +158,7 @@ void sendOwnerReservationReminderEmail_Success() throws MessagingException { @Nested class SendCancellationConfirmationEmailGroup { @Test - void sendCancellationConfirmationEmail_Success() throws MessagingException { + void sendCancellationConfirmationEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendCancellationConfirmationEmail(any(Reservation.class)); emailServiceHelper.sendCancellationConfirmationEmail(reservation); @@ -170,7 +170,7 @@ void sendCancellationConfirmationEmail_Success() throws MessagingException { @Nested class SendCancellationByOwnerNotificationEmailGroup { @Test - void sendCancellationByOwnerNotificationEmail_Success() throws MessagingException { + void sendCancellationByOwnerNotificationEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendCancellationByOwnerNotificationEmail(any(Reservation.class)); emailServiceHelper.sendCancellationByOwnerNotificationEmail(reservation); @@ -182,7 +182,7 @@ void sendCancellationByOwnerNotificationEmail_Success() throws MessagingExceptio @Nested class SendCancellationNotificationToOwnerEmailGroup { @Test - void sendCancellationNotificationToOwnerEmail_Success() throws MessagingException { + void sendCancellationNotificationToOwnerEmail_Success_shouldCallEmailService() throws MessagingException { doNothing().when(emailService).sendCancellationNotificationToOwnerEmail(any(Reservation.class)); emailServiceHelper.sendCancellationNotificationToOwnerEmail(reservation); @@ -194,7 +194,7 @@ void sendCancellationNotificationToOwnerEmail_Success() throws MessagingExceptio @Nested class HandleNewReservationEmailsGroup { @Test - void handleNewReservationEmails_SendsBothEmails() throws MessagingException { + void handleNewReservationEmails_Success_shouldSendBothEmails() throws MessagingException { doNothing().when(emailService).sendGuestReservationConfirmationEmail(any(Reservation.class), any(BigDecimal.class)); doNothing().when(emailService).sendOwnerReservedNotification(any(Reservation.class)); @@ -208,7 +208,7 @@ void handleNewReservationEmails_SendsBothEmails() throws MessagingException { @Nested class HandleGuestCancellationEmailsGroup { @Test - void handleGuestCancellationEmails_SendsBothEmails() throws MessagingException { + void handleGuestCancellationEmails_Success_shouldSendBothEmails() throws MessagingException { doNothing().when(emailService).sendCancellationConfirmationEmail(any(Reservation.class)); doNothing().when(emailService).sendCancellationNotificationToOwnerEmail(any(Reservation.class)); @@ -222,7 +222,7 @@ void handleGuestCancellationEmails_SendsBothEmails() throws MessagingException { @Nested class HandleOwnerCancellationEmailsGroup { @Test - void handleOwnerCancellationEmails_SendsNotification() throws MessagingException { + void handleOwnerCancellationEmails_Success_shouldSendNotification() throws MessagingException { doNothing().when(emailService).sendCancellationByOwnerNotificationEmail(any(Reservation.class)); emailServiceHelper.handleOwnerCancellationEmails(reservation); @@ -234,7 +234,7 @@ void handleOwnerCancellationEmails_SendsNotification() throws MessagingException @Nested class SendReservationRemindersGroup { @Test - void sendReservationReminders_SendsBothReminders() throws MessagingException { + void sendReservationReminders_Success_shouldSendBothReminders() throws MessagingException { doNothing().when(emailService).sendGuestReservationReminderEmail(any(Reservation.class)); doNothing().when(emailService).sendOwnerReservationReminderEmail(any(Reservation.class)); diff --git a/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTest.java b/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTest.java index 1a9befb..d6e7026 100644 --- a/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTest.java +++ b/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTest.java @@ -65,7 +65,7 @@ void setUp() { } @Test - void sendWelcomeEmail_Success() throws MessagingException { + void sendWelcomeEmail_validUser_shouldUseWelcomeTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("welcome"), any(Context.class))) .thenReturn("Welcome Email"); @@ -78,7 +78,7 @@ void sendWelcomeEmail_Success() throws MessagingException { } @Test - void sendOwnerReservedNotification_Success() throws MessagingException { + void sendOwnerReservedNotification_validReservation_shouldUseNotificationTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("owner_reservation_notification"), any(Context.class))) .thenReturn("Owner Notification"); @@ -91,7 +91,7 @@ void sendOwnerReservedNotification_Success() throws MessagingException { } @Test - void sendGuestReservationConfirmationEmail_Success() throws MessagingException { + void sendGuestReservationConfirmationEmail_validReservation_shouldUseConfirmationTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("guest_reservation_confirmation"), any(Context.class))) .thenReturn("Confirmation"); @@ -103,7 +103,7 @@ void sendGuestReservationConfirmationEmail_Success() throws MessagingException { } @Test - void sendGuestReservationReminderEmail_Success() throws MessagingException { + void sendGuestReservationReminderEmail_validReservation_shouldUseReminderTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("guest_reminder"), any(Context.class))) .thenReturn("Reminder"); @@ -115,7 +115,7 @@ void sendGuestReservationReminderEmail_Success() throws MessagingException { } @Test - void sendOwnerReservationReminderEmail_Success() throws MessagingException { + void sendOwnerReservationReminderEmail_validReservation_shouldUseOwnerReminderTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("owner_reminder"), any(Context.class))) .thenReturn("Owner Reminder"); @@ -127,7 +127,7 @@ void sendOwnerReservationReminderEmail_Success() throws MessagingException { } @Test - void sendCancellationConfirmationEmail_Success() throws MessagingException { + void sendCancellationConfirmationEmail_validReservation_shouldUseGuestCancellationTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("guest_cancellationByGuest"), any(Context.class))) .thenReturn("Cancellation"); @@ -139,7 +139,7 @@ void sendCancellationConfirmationEmail_Success() throws MessagingException { } @Test - void sendCancellationByOwnerNotificationEmail_Success() throws MessagingException { + void sendCancellationByOwnerNotificationEmail_validReservation_shouldUseOwnerCancellationTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("guest_cancellationByOwner"), any(Context.class))) .thenReturn("Cancellation by Owner"); @@ -151,7 +151,7 @@ void sendCancellationByOwnerNotificationEmail_Success() throws MessagingExceptio } @Test - void sendCancellationNotificationToOwnerEmail_Success() throws MessagingException { + void sendCancellationNotificationToOwnerEmail_validReservation_shouldUseOwnerNotificationTemplateAndSend() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(eq("owner_cancellationByGuest"), any(Context.class))) .thenReturn("Cancellation to Owner"); @@ -163,7 +163,7 @@ void sendCancellationNotificationToOwnerEmail_Success() throws MessagingExceptio } @Test - void allEmailMethods_UseCorrectEncoding() throws MessagingException { + void sendEmailMethods_defaultBehavior_shouldCreateMimeMessageOnce() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(anyString(), any(Context.class))) .thenReturn("Email"); @@ -174,7 +174,7 @@ void allEmailMethods_UseCorrectEncoding() throws MessagingException { } @Test - void allEmailMethods_SetCorrectSubjects() throws MessagingException { + void sendEmailMethods_multipleCalls_shouldVerifyInteractions() throws MessagingException { when(mailSender.createMimeMessage()).thenReturn(mimeMessage); when(templateEngine.process(anyString(), any(Context.class))) .thenReturn("Email"); diff --git a/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTestEmail.java b/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTestEmail.java index 4b6218c..d4beeb5 100644 --- a/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTestEmail.java +++ b/src/test/java/com/SleepUp/SU/utils/EmailServiceImplTestEmail.java @@ -69,49 +69,49 @@ public void setUp() { } @Test - public void testSendWelcomeEmail() throws MessagingException { + public void sendWelcomeEmail_validUser_shouldSendMimeMessage() throws MessagingException { emailService.sendWelcomeEmail(guest); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendOwnerReservedNotification() throws MessagingException { + public void sendOwnerReservedNotification_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendOwnerReservedNotification(reservation); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendGuestReservationConfirmationEmail() throws MessagingException { + public void sendGuestReservationConfirmationEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendGuestReservationConfirmationEmail(reservation, new BigDecimal("100.00")); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendGuestReservationReminderEmail() throws MessagingException { + public void sendGuestReservationReminderEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendGuestReservationReminderEmail(reservation); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendOwnerReservationReminderEmail() throws MessagingException { + public void sendOwnerReservationReminderEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendOwnerReservationReminderEmail(reservation); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendCancellationConfirmationEmail() throws MessagingException { + public void sendCancellationConfirmationEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendCancellationConfirmationEmail(reservation); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendCancellationByOwnerNotificationEmail() throws MessagingException { + public void sendCancellationByOwnerNotificationEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendCancellationByOwnerNotificationEmail(reservation); verify(mailSender).send(any(MimeMessage.class)); } @Test - public void testSendCancellationNotificationToOwnerEmail() throws MessagingException { + public void sendCancellationNotificationToOwnerEmail_validReservation_shouldSendMimeMessage() throws MessagingException { emailService.sendCancellationNotificationToOwnerEmail(reservation); verify(mailSender).send(any(MimeMessage.class)); } diff --git a/src/test/java/com/SleepUp/SU/utils/EmailServiceMailHogIntegrationTest.java b/src/test/java/com/SleepUp/SU/utils/EmailServiceMailHogIntegrationTest.java index 820c8cd..f57edb9 100644 --- a/src/test/java/com/SleepUp/SU/utils/EmailServiceMailHogIntegrationTest.java +++ b/src/test/java/com/SleepUp/SU/utils/EmailServiceMailHogIntegrationTest.java @@ -51,49 +51,49 @@ void setUp() { } @Test - public void testSendWelcomeEmail() throws MessagingException, InterruptedException { + public void integration_sendWelcomeEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendWelcomeEmail(guest); Thread.sleep(1000); } @Test - public void testSendOwnerReservedNotification() throws MessagingException, InterruptedException { + public void integration_sendOwnerReservedNotification_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendOwnerReservedNotification(reservation); Thread.sleep(1000); } @Test - public void testSendGuestReservationConfirmationEmail() throws MessagingException, InterruptedException { + public void integration_sendGuestReservationConfirmationEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendGuestReservationConfirmationEmail(reservation, new BigDecimal("100.00")); Thread.sleep(1000); } @Test - public void testSendGuestReservationReminderEmail() throws MessagingException, InterruptedException { + public void integration_sendGuestReservationReminderEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendGuestReservationReminderEmail(reservation); Thread.sleep(1000); } @Test - public void testSendOwnerReservationReminderEmail() throws MessagingException, InterruptedException { + public void integration_sendOwnerReservationReminderEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendOwnerReservationReminderEmail(reservation); Thread.sleep(1000); } @Test - public void testSendCancellationConfirmationEmail() throws MessagingException, InterruptedException { + public void integration_sendCancellationConfirmationEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendCancellationConfirmationEmail(reservation); Thread.sleep(1000); } @Test - public void testSendCancellationByOwnerNotificationEmail() throws MessagingException, InterruptedException { + public void integration_sendCancellationByOwnerNotificationEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendCancellationByOwnerNotificationEmail(reservation); Thread.sleep(1000); } @Test - public void testSendCancellationNotificationToOwnerEmail() throws MessagingException, InterruptedException { + public void integration_sendCancellationNotificationToOwnerEmail_shouldNotThrowException() throws MessagingException, InterruptedException { emailService.sendCancellationNotificationToOwnerEmail(reservation); Thread.sleep(1000); }