|
@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
|
|
public class NotificationServiceTest {
|
|
public class NotificationServiceTest {
|
|
@@ -54,4 +55,28 @@ public class NotificationServiceTest {
|
|
|
System.out.println("Content: " + expectedContent);
|
|
System.out.println("Content: " + expectedContent);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void testSendNotificationsWithException() throws Exception {
|
|
|
|
|
+ MailService mailServiceMock = mock(MailService.class);
|
|
|
|
|
+ NotificationService notificationService = new NotificationServiceImpl(mailServiceMock);
|
|
|
|
|
+
|
|
|
|
|
+ User user = new User("Jan", "Kowalski", "jan.kowalski@example.com");
|
|
|
|
|
+ List<String> recipients = Arrays.asList("recipient1@example.com", "recipient2@example.com");
|
|
|
|
|
+ String subject = "Testowy temat";
|
|
|
|
|
+ String content = "Treść wiadomości";
|
|
|
|
|
+
|
|
|
|
|
+ doThrow(new RuntimeException("Email sending failed"))
|
|
|
|
|
+ .doNothing()
|
|
|
|
|
+ .when(mailServiceMock).sendEmail(anyString(), eq("recipient1@example.com"), anyString(), anyString());
|
|
|
|
|
+
|
|
|
|
|
+ assertThrows(RuntimeException.class, () -> {
|
|
|
|
|
+ notificationService.sendNotifications(user, recipients, subject, content);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ String expectedSubject = "Powiadomienie: Testowy temat";
|
|
|
|
|
+ String expectedContent = "Powiadomienie od Jan Kowalski\nTreść wiadomości";
|
|
|
|
|
+ verify(mailServiceMock).sendEmail(user.getEmail(), "recipient1@example.com", expectedSubject, expectedContent);
|
|
|
|
|
+ verify(mailServiceMock, never()).sendEmail(user.getEmail(), "recipient2@example.com", expectedSubject, expectedContent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|