Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/test/java/com/SleepUp/SU/utils/EmailServiceHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));

Expand All @@ -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));

Expand All @@ -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);
Expand All @@ -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));

Expand Down
20 changes: 10 additions & 10 deletions src/test/java/com/SleepUp/SU/utils/EmailServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("<html>Welcome Email</html>");
Expand All @@ -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("<html>Owner Notification</html>");
Expand All @@ -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("<html>Confirmation</html>");
Expand All @@ -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("<html>Reminder</html>");
Expand All @@ -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("<html>Owner Reminder</html>");
Expand All @@ -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("<html>Cancellation</html>");
Expand All @@ -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("<html>Cancellation by Owner</html>");
Expand All @@ -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("<html>Cancellation to Owner</html>");
Expand All @@ -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("<html>Email</html>");
Expand All @@ -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("<html>Email</html>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading