Explorar o código

Pierwsza wersja projektu notificationSystem

Adam Matuszewski hai 1 ano
pai
achega
93f9711f9b

+ 8 - 0
NotificationSystem/.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 19 - 0
NotificationSystem/.idea/compiler.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <excludeFromCompile>
+      <directory url="file://$PROJECT_DIR$/src/main/resources/archetype-resources" includeSubdirectories="true" />
+    </excludeFromCompile>
+    <annotationProcessing>
+      <profile name="Maven default annotation processors profile" enabled="true">
+        <sourceOutputDir name="target/generated-sources/annotations" />
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+        <outputRelativeToContentRoot value="true" />
+        <module name="app" />
+      </profile>
+    </annotationProcessing>
+    <bytecodeTargetLevel>
+      <module name="NotificationSystem" target="11" />
+    </bytecodeTargetLevel>
+  </component>
+</project>

+ 7 - 0
NotificationSystem/.idea/encodings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+  </component>
+</project>

+ 20 - 0
NotificationSystem/.idea/jarRepositories.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RemoteRepositoriesConfiguration">
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Central Repository" />
+      <option name="url" value="https://repo.maven.apache.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="jboss.community" />
+      <option name="name" value="JBoss Community repository" />
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+    </remote-repository>
+  </component>
+</project>

+ 14 - 0
NotificationSystem/.idea/misc.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 124 - 0
NotificationSystem/.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 6 - 0
NotificationSystem/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 73 - 0
NotificationSystem/pom.xml

@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>pl.dmcs</groupId>
+  <artifactId>app</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>11</maven.compiler.source>
+    <maven.compiler.target>11</maven.compiler.target>
+  </properties>
+  <name>My sample project</name>
+  <description>This is my sample project.</description>
+  <url>https://weeia.p.lodz.pl</url>
+  <dependencies>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <version>5.10.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>5.11.0</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.3.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.3.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.12.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>3.2.5</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.3.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>3.1.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>3.1.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>4.0.0-M13</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-project-info-reports-plugin</artifactId>
+          <version>3.5.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

+ 12 - 0
NotificationSystem/src/main/java/pl/dmcs/MailService.java

@@ -0,0 +1,12 @@
+package pl.dmcs;
+
+import pl.dmcs.exceptions.MailException;
+
+public class MailService {
+    public void sendEmail(String from, String to, String subject, String content) throws MailException {
+        if (Math.random() < 0.1) {
+            throw new MailException("Nie udało się wysłać wiadomości do " + to);
+        }
+        System.out.println("Wysłano email do " + to);
+    }
+}

+ 17 - 0
NotificationSystem/src/main/java/pl/dmcs/Main.java

@@ -0,0 +1,17 @@
+package pl.dmcs;
+
+import java.io.IOException;
+
+import pl.dmcs.exceptions.NotificationException;
+
+public class Main {
+    public static void main(String[] args) {
+        MailService mailService = new MailService();
+        NotificationService notificationService = new NotificationService(mailService);
+        try {
+            notificationService.sendNotifications("src/main/resources/notifications.txt");
+        } catch (IOException | NotificationException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 54 - 0
NotificationSystem/src/main/java/pl/dmcs/NotificationService.java

@@ -0,0 +1,54 @@
+package pl.dmcs;
+
+import pl.dmcs.exceptions.MailException;
+import pl.dmcs.exceptions.NotificationException;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NotificationService {
+    private MailService mailService;
+
+    public NotificationService(MailService mailService) {
+        this.mailService = mailService;
+    }
+
+    public void sendNotifications(String filePath) throws IOException, NotificationException {
+        BufferedReader reader = new BufferedReader(new FileReader(filePath));
+        String senderName = reader.readLine();
+        String senderEmail = reader.readLine();
+        List<String> recipients = new ArrayList<>();
+        String recipient;
+
+        while ((recipient = reader.readLine()) != null) {
+            recipients.add(recipient);
+        }
+
+        reader.close();
+
+        String subject = "Powiadomienie: Temat powiadomienia";
+        String content = "Powiadomienie od " + senderName + "\nTreść powiadomienia";
+
+        List<String> failedRecipients = new ArrayList<>();
+        for (String recipientEmail : recipients) {
+            try {
+                mailService.sendEmail(senderEmail, recipientEmail, subject, content);
+            } catch (MailException e) {
+                failedRecipients.add(recipientEmail);
+            }
+        }
+
+        if (!failedRecipients.isEmpty()) {
+            try {
+                String failureSubject = "Powiadomienie: Niepowodzenie wysłania wiadomości";
+                String failureContent = "Nie udało się dostarczyć wiadomości do następujących adresatów: " + String.join(", ", failedRecipients);
+                mailService.sendEmail(senderEmail, senderEmail, failureSubject, failureContent);
+            } catch (MailException e) {
+                throw new NotificationException("Nie udało się wysłać wiadomości zwrotnej", failedRecipients, e);
+            }
+        }
+    }
+}

+ 7 - 0
NotificationSystem/src/main/java/pl/dmcs/exceptions/MailException.java

@@ -0,0 +1,7 @@
+package pl.dmcs.exceptions;
+
+public class MailException extends Exception {
+    public MailException(String message) {
+        super(message);
+    }
+}

+ 16 - 0
NotificationSystem/src/main/java/pl/dmcs/exceptions/NotificationException.java

@@ -0,0 +1,16 @@
+package pl.dmcs.exceptions;
+
+import java.util.List;
+
+public class NotificationException extends Exception {
+    private List<String> failedRecipients;
+
+    public NotificationException(String message, List<String> failedRecipients, Throwable cause) {
+        super(message, cause);
+        this.failedRecipients = failedRecipients;
+    }
+
+    public List<String> getFailedRecipients() {
+        return failedRecipients;
+    }
+}

+ 9 - 0
NotificationSystem/src/main/resources/META-INF/maven/archetype.xml

@@ -0,0 +1,9 @@
+<archetype>
+  <id>NotificationSystem</id>
+  <sources>
+    <source>src/main/java/App.java</source>
+  </sources>
+  <testSources>
+    <source>src/test/java/AppTest.java</source>
+  </testSources>
+</archetype>

+ 15 - 0
NotificationSystem/src/main/resources/archetype-resources/pom.xml

@@ -0,0 +1,15 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>$org.example</groupId>
+  <artifactId>$NotificationSystem</artifactId>
+  <version>$1.0-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

+ 13 - 0
NotificationSystem/src/main/resources/archetype-resources/src/main/java/App.java

@@ -0,0 +1,13 @@
+package $org.example;
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}

+ 38 - 0
NotificationSystem/src/main/resources/archetype-resources/src/test/java/AppTest.java

@@ -0,0 +1,38 @@
+package $org.example;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

+ 41 - 0
NotificationSystem/src/test/java/pl/dmcs/MailServiceTest.java

@@ -0,0 +1,41 @@
+package pl.dmcs;
+
+import pl.dmcs.exceptions.MailException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class MailServiceTest {
+
+    // Test for successful email sending
+    @Test
+    public void testSendEmailSuccessful() {
+        MailService mailService = new MailService();
+        try {
+            mailService.sendEmail("test@example.com", "recipient@example.com", "Test", "Test content");
+        } catch (MailException e) {
+            fail("MailException thrown during successful sendEmail test");
+        }
+    }
+
+    // Test for email sending failure
+    @Test
+    public void testSendEmailFailure() {
+        // Create a subclass of MailService that always fails
+        class FailingMailService extends MailService {
+            @Override
+            public void sendEmail(String from, String to, String subject, String content) throws MailException {
+                throw new MailException("Forced failure");
+            }
+        }
+
+        MailService mailService = new FailingMailService();
+        boolean exceptionThrown = false;
+        try {
+            mailService.sendEmail("test@example.com", "recipient@example.com", "Test", "Test content");
+        } catch (MailException e) {
+            exceptionThrown = true;
+        }
+        assertTrue(exceptionThrown, "Expected MailException to be thrown");
+    }
+}

+ 58 - 0
NotificationSystem/src/test/java/pl/dmcs/NotificationServiceTest.java

@@ -0,0 +1,58 @@
+package pl.dmcs;
+
+import pl.dmcs.exceptions.MailException;
+import pl.dmcs.exceptions.NotificationException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+public class NotificationServiceTest {
+    private MailService mailServiceMock;
+    private NotificationService notificationService;
+
+    @BeforeEach
+    public void setUp() {
+        mailServiceMock = Mockito.mock(MailService.class);
+        notificationService = new NotificationService(mailServiceMock);
+    }
+
+    @Test
+    public void testSendNotificationsSuccessful() throws IOException, MailException, NotificationException {
+        doNothing().when(mailServiceMock).sendEmail(anyString(), anyString(), anyString(), anyString());
+
+        notificationService.sendNotifications("src/test/resources/notifications_test.txt");
+
+        verify(mailServiceMock, times(3)).sendEmail(anyString(), anyString(), anyString(), anyString());
+    }
+
+    @Test
+    public void testSendNotificationsFailure() throws IOException, MailException, NotificationException {
+        doThrow(new MailException("Error")).when(mailServiceMock).sendEmail(eq("jan.kowalski@example.com"), eq("adam.nowak@example.com"), anyString(), anyString());
+        doNothing().when(mailServiceMock).sendEmail(eq("jan.kowalski@example.com"), eq("jan.kowalski@example.com"), anyString(), anyString());
+
+        notificationService.sendNotifications("src/test/resources/notifications_test.txt");
+
+        verify(mailServiceMock, times(1)).sendEmail(eq("jan.kowalski@example.com"), eq("adam.nowak@example.com"), anyString(), anyString());
+        verify(mailServiceMock, times(1)).sendEmail(eq("jan.kowalski@example.com"), eq("jan.kowalski@example.com"), anyString(), anyString());
+    }
+
+    @Test
+    public void testSendNotificationsFailureAndReturnMailFailure() throws IOException, MailException {
+        doThrow(new MailException("Error")).when(mailServiceMock).sendEmail(eq("jan.kowalski@example.com"), eq("adam.nowak@example.com"), anyString(), anyString());
+        doThrow(new MailException("Return mail failure")).when(mailServiceMock).sendEmail(eq("jan.kowalski@example.com"), eq("jan.kowalski@example.com"), anyString(), anyString());
+
+        try {
+            notificationService.sendNotifications("src/test/resources/notifications_test.txt");
+        } catch (NotificationException e) {
+            assertEquals("Nie udało się wysłać wiadomości zwrotnej", e.getMessage());
+            assertEquals(1, e.getFailedRecipients().size());
+            assertTrue(e.getFailedRecipients().contains("adam.nowak@example.com"));
+        }
+    }
+}

+ 5 - 0
NotificationSystem/src/test/resources/notifications_test.txt

@@ -0,0 +1,5 @@
+Jan Kowalski
+jan.kowalski@example.com
+adam.nowak@example.com
+ewa.kwiatkowska@example.com
+tomasz.zielinski@example.com