| 1 |
|
package org.europa.together.domain; |
| 2 |
|
|
| 3 |
|
import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; |
| 4 |
|
import java.util.ArrayList; |
| 5 |
|
import java.util.List; |
| 6 |
|
import org.europa.together.JUnit5Preperator; |
| 7 |
|
import org.europa.together.application.LogbackLogger; |
| 8 |
|
import org.europa.together.business.Logger; |
| 9 |
|
import org.europa.together.utils.Constraints; |
| 10 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 11 |
|
import static org.junit.jupiter.api.Assertions.*; |
| 12 |
|
import org.junit.jupiter.api.Test; |
| 13 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
| 14 |
|
|
| 15 |
|
@SuppressWarnings("unchecked") |
| 16 |
|
@ExtendWith({JUnit5Preperator.class}) |
| |
|
| 100% |
Uncovered Elements: 0 (117) |
Complexity: 16 |
Complexity Density: 0.16 |
|
| 17 |
|
public class MailTest { |
| 18 |
|
|
| 19 |
|
private static final Logger LOGGER = new LogbackLogger(MailTest.class); |
| 20 |
|
|
| 21 |
|
private static final String DIRECTORY |
| 22 |
|
= Constraints.SYSTEM_APP_DIR + "/target/test-classes"; |
| 23 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 24 |
1 |
@Test... |
| 25 |
|
void constructor() { |
| 26 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
| 27 |
|
|
| 28 |
1 |
assertThat(Mail.class, hasValidBeanConstructor()); |
| 29 |
|
} |
| 30 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 31 |
1 |
@Test... |
| 32 |
|
void getDefaultMimeType() { |
| 33 |
1 |
LOGGER.log("TEST CASE: getDefaultMimeType", LogLevel.DEBUG); |
| 34 |
|
|
| 35 |
1 |
Mail mail = new Mail(); |
| 36 |
1 |
assertEquals("plain", mail.getMimeType()); |
| 37 |
|
} |
| 38 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 39 |
1 |
@Test... |
| 40 |
|
void setHtmlMimeType() { |
| 41 |
1 |
LOGGER.log("TEST CASE: setHtmlMimeType", LogLevel.DEBUG); |
| 42 |
|
|
| 43 |
1 |
Mail mail = new Mail(); |
| 44 |
1 |
mail.setMimeTypeToHTML(); |
| 45 |
1 |
assertEquals("html", mail.getMimeType()); |
| 46 |
|
} |
| 47 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 48 |
1 |
@Test... |
| 49 |
|
void setPlainMimeType() { |
| 50 |
1 |
LOGGER.log("TEST CASE: setPlainMimeType", LogLevel.DEBUG); |
| 51 |
|
|
| 52 |
1 |
Mail mail = new Mail(); |
| 53 |
1 |
mail.setMimeTypeToHTML(); |
| 54 |
1 |
mail.setMimeTypeToText(); |
| 55 |
1 |
assertEquals("plain", mail.getMimeType()); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 58 |
1 |
@Test... |
| 59 |
|
void recipients() throws Exception { |
| 60 |
1 |
LOGGER.log("TEST CASE: recipients", LogLevel.DEBUG); |
| 61 |
|
|
| 62 |
1 |
Mail mail = new Mail(); |
| 63 |
1 |
LOGGER.log("Inital empty recipient list.", LogLevel.DEBUG); |
| 64 |
1 |
assertEquals(0, mail.getRecipentList().size()); |
| 65 |
|
|
| 66 |
1 |
mail.addRecipent("user_01@sample.org"); |
| 67 |
1 |
assertEquals(1, mail.getRecipentList().size()); |
| 68 |
1 |
assertEquals("user_01@sample.org", mail.getRecipentList().get(0).getAddress()); |
| 69 |
|
|
| 70 |
1 |
mail.addRecipent("user_02@sample.org"); |
| 71 |
1 |
assertEquals(2, mail.getRecipentList().size()); |
| 72 |
1 |
assertEquals("user_02@sample.org", mail.getRecipentList().get(1).getAddress()); |
| 73 |
|
|
| 74 |
1 |
LOGGER.log("Clear recipient list.", LogLevel.DEBUG); |
| 75 |
1 |
mail.clearRecipents(); |
| 76 |
1 |
assertEquals(0, mail.getRecipentList().size()); |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 79 |
1 |
@Test... |
| 80 |
|
void addRecipentDetectDoubleEntries() throws Exception { |
| 81 |
1 |
LOGGER.log("TEST CASE: addRecipentDetectDoubleEntries", LogLevel.DEBUG); |
| 82 |
|
|
| 83 |
1 |
Mail mail = new Mail(); |
| 84 |
1 |
mail.addRecipent("success@domain.test"); |
| 85 |
1 |
mail.addRecipent("success@domain.test"); |
| 86 |
1 |
mail.addRecipent("no_mail@domain.eu"); |
| 87 |
1 |
mail.addRecipent("no_mail@domain.eu"); |
| 88 |
1 |
assertEquals(2, mail.getRecipentList().size()); |
| 89 |
|
} |
| 90 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 91 |
1 |
@Test... |
| 92 |
|
void addRecipentValidationFail() throws Exception { |
| 93 |
1 |
LOGGER.log("TEST CASE: addRecipentValidationFail", LogLevel.DEBUG); |
| 94 |
|
|
| 95 |
1 |
Mail mail = new Mail(); |
| 96 |
|
|
| 97 |
1 |
assertThrows(Exception.class, () -> { |
| 98 |
1 |
assertFalse(mail.addRecipent("@domain")); |
| 99 |
|
}); |
| 100 |
1 |
assertThrows(Exception.class, () -> { |
| 101 |
1 |
assertFalse(mail.addRecipent("no_mail.domain")); |
| 102 |
|
}); |
| 103 |
1 |
assertThrows(Exception.class, () -> { |
| 104 |
1 |
assertFalse(mail.addRecipent("success@domain")); |
| 105 |
|
}); |
| 106 |
1 |
assertThrows(Exception.class, () -> { |
| 107 |
1 |
assertFalse(mail.addRecipent("fail")); |
| 108 |
|
}); |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 111 |
1 |
@Test... |
| 112 |
|
void addRecipientList() throws Exception { |
| 113 |
1 |
LOGGER.log("TEST CASE: addRecipientList", LogLevel.DEBUG); |
| 114 |
|
|
| 115 |
1 |
List<String> recipients = new ArrayList<>(); |
| 116 |
1 |
recipients.add("test@sample.com"); |
| 117 |
1 |
recipients.add("test_01@sample.com"); |
| 118 |
1 |
recipients.add("test_02@sample.com"); |
| 119 |
1 |
recipients.add("test_03@sample.com"); |
| 120 |
1 |
recipients.add("test@sample.com"); |
| 121 |
|
|
| 122 |
1 |
Mail mail = new Mail(); |
| 123 |
1 |
mail.addRecipientList(recipients); |
| 124 |
1 |
assertEquals(4, mail.getRecipentList().size()); |
| 125 |
|
} |
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 127 |
1 |
@Test... |
| 128 |
|
void content() { |
| 129 |
1 |
LOGGER.log("TEST CASE: content", LogLevel.DEBUG); |
| 130 |
|
|
| 131 |
1 |
String content = "<h1>E Mail>/h1><p>this is the content of the email."; |
| 132 |
1 |
Mail mail = new Mail(); |
| 133 |
1 |
mail.setMessage(content); |
| 134 |
1 |
assertEquals(content, mail.getMessage()); |
| 135 |
|
} |
| 136 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 137 |
1 |
@Test... |
| 138 |
|
void subject() { |
| 139 |
1 |
LOGGER.log("TEST CASE: subject", LogLevel.DEBUG); |
| 140 |
|
|
| 141 |
1 |
String subject = "E-MAil Topic"; |
| 142 |
1 |
Mail mail = new Mail(); |
| 143 |
1 |
mail.setSubject(subject); |
| 144 |
1 |
assertEquals(subject, mail.getSubject()); |
| 145 |
|
} |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 147 |
1 |
@Test... |
| 148 |
|
void attachments() { |
| 149 |
1 |
LOGGER.log("TEST CASE: attachments", LogLevel.DEBUG); |
| 150 |
|
|
| 151 |
1 |
Mail mail = new Mail(); |
| 152 |
1 |
LOGGER.log("Inital empty attachment list.", LogLevel.DEBUG); |
| 153 |
1 |
assertEquals(0, mail.getAttachmentList().size()); |
| 154 |
|
|
| 155 |
1 |
mail.addAttachment(DIRECTORY + "/Attachment.pdf"); |
| 156 |
1 |
assertEquals(1, mail.getAttachmentList().size()); |
| 157 |
|
|
| 158 |
1 |
mail.addAttachment(DIRECTORY + "/TestFile"); |
| 159 |
1 |
assertEquals(2, mail.getAttachmentList().size()); |
| 160 |
|
|
| 161 |
1 |
LOGGER.log("Clear attachment list.", LogLevel.DEBUG); |
| 162 |
1 |
mail.clearAttachments(); |
| 163 |
1 |
assertEquals(0, mail.getAttachmentList().size()); |
| 164 |
|
} |
| 165 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 166 |
1 |
@Test... |
| 167 |
|
void failAddEmptyAttachment() { |
| 168 |
1 |
LOGGER.log("TEST CASE: failAddEmptyAttachment", LogLevel.DEBUG); |
| 169 |
|
|
| 170 |
1 |
Mail mail = new Mail(); |
| 171 |
1 |
assertFalse(mail.addAttachment(DIRECTORY + "/empty.attachment")); |
| 172 |
1 |
assertEquals(0, mail.getAttachmentList().size()); |
| 173 |
|
} |
| 174 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 175 |
1 |
@Test... |
| 176 |
|
void failAddNotExistingAttachment() { |
| 177 |
1 |
LOGGER.log("TEST CASE: failAddNotExistingAttachment", LogLevel.DEBUG); |
| 178 |
|
|
| 179 |
1 |
Mail mail = new Mail(); |
| 180 |
1 |
assertFalse(mail.addAttachment(DIRECTORY + "/FileNotExist.pdf")); |
| 181 |
1 |
assertEquals(0, mail.getAttachmentList().size()); |
| 182 |
|
} |
| 183 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 184 |
1 |
@Test... |
| 185 |
|
void attachmentSize() { |
| 186 |
1 |
LOGGER.log("TEST CASE: attachmentSize", LogLevel.DEBUG); |
| 187 |
|
|
| 188 |
1 |
Mail mail = new Mail(); |
| 189 |
1 |
assertEquals(-1, mail.getAttachmentSize()); |
| 190 |
1 |
mail.setAttachmentSize(100); |
| 191 |
1 |
assertEquals(100, mail.getAttachmentSize()); |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 194 |
1 |
@Test... |
| 195 |
|
void addAttachmentLimitSize() { |
| 196 |
1 |
LOGGER.log("TEST CASE: addAttachmentLimitSize", LogLevel.DEBUG); |
| 197 |
|
|
| 198 |
1 |
Mail mail = new Mail(); |
| 199 |
1 |
mail.setAttachmentSize(100); |
| 200 |
1 |
assertFalse(mail.addAttachment(DIRECTORY + "/Attachment.pdf")); |
| 201 |
1 |
assertTrue(mail.addAttachment(DIRECTORY + "/TestFile")); |
| 202 |
1 |
assertEquals(1, mail.getAttachmentList().size()); |
| 203 |
|
} |
| 204 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 205 |
1 |
@Test... |
| 206 |
|
void addAttachmentList() { |
| 207 |
1 |
LOGGER.log("TEST CASE: addAttachmentList", LogLevel.DEBUG); |
| 208 |
|
|
| 209 |
1 |
List<String> attachments = new ArrayList<>(); |
| 210 |
1 |
attachments.add(DIRECTORY + "/Attachment.pdf"); |
| 211 |
1 |
attachments.add(DIRECTORY + "/TestFile"); |
| 212 |
1 |
Mail mail = new Mail(); |
| 213 |
1 |
mail.addAttachmentList(attachments); |
| 214 |
1 |
assertEquals(2, mail.getAttachmentList().size()); |
| 215 |
|
} |
| 216 |
|
} |