|
1 | 1 | /************************************************* |
2 | 2 | * MailerSend Java SDK |
3 | 3 | * https://github.com/mailersend/mailersend-java |
4 | | - * |
| 4 | + * |
5 | 5 | * @author MailerSend <support@mailersend.com> |
6 | 6 | * https://mailersend.com |
7 | 7 | **************************************************/ |
|
16 | 16 | import com.mailersend.sdk.emails.Personalization; |
17 | 17 |
|
18 | 18 | public class EmailConfigurationTest { |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * Tests the from name and email |
22 | 22 | */ |
23 | 23 | @Test |
24 | 24 | public void TestEmailFromConfiguration() { |
25 | | - |
| 25 | + |
26 | 26 | Email email = TestHelper.createBasicEmail(true); |
27 | | - |
| 27 | + |
28 | 28 | email.setFrom(TestHelper.fromName, TestHelper.emailFrom); |
29 | 29 |
|
30 | 30 | assertEquals(email.from.name, TestHelper.fromName); |
31 | 31 | assertEquals(email.from.email, TestHelper.emailFrom); |
32 | 32 | } |
33 | | - |
34 | | - |
| 33 | + |
| 34 | + |
35 | 35 | /** |
36 | 36 | * Tests that a single recipient can be added |
37 | 37 | */ |
38 | 38 | @Test |
39 | 39 | public void TestSingleRecipientConfiguration() { |
40 | | - |
| 40 | + |
41 | 41 | Email email = TestHelper.createBasicEmail(true); |
42 | | - |
| 42 | + |
43 | 43 | assertEquals(email.recipients.size(), 1); |
44 | | - |
| 44 | + |
45 | 45 | assertEquals(email.recipients.get(0).name, TestHelper.toName); |
46 | | - |
| 46 | + |
47 | 47 | assertEquals(email.recipients.get(0).email, TestHelper.toEmail); |
48 | 48 | } |
49 | | - |
50 | | - |
| 49 | + |
| 50 | + |
51 | 51 | /** |
52 | 52 | * Tests that multiple recipients can be added |
53 | 53 | */ |
54 | 54 | @Test |
55 | 55 | public void TestMultipleRecipientsConfiguration() { |
56 | | - |
| 56 | + |
57 | 57 | String secondRecipientName = "Test Recipient 2"; |
58 | 58 | String secondRecipientEmail = "test@recipient2.com"; |
59 | | - |
| 59 | + |
60 | 60 | Email email = TestHelper.createBasicEmail(true); |
61 | | - |
| 61 | + |
62 | 62 | email.addRecipient(secondRecipientName, secondRecipientEmail); |
63 | | - |
| 63 | + |
64 | 64 | assertEquals(email.recipients.size(), 2); |
65 | | - |
| 65 | + |
66 | 66 | assertEquals(email.recipients.get(1).name, secondRecipientName); |
67 | 67 | assertEquals(email.recipients.get(1).email, secondRecipientEmail); |
68 | 68 | } |
69 | | - |
70 | | - |
| 69 | + |
| 70 | + |
71 | 71 | /** |
72 | 72 | * Tests that the subject, and html and plain bodies are added to the email |
73 | 73 | */ |
74 | 74 | @Test |
75 | 75 | public void TestEmailContentsConfiguration() { |
76 | | - |
| 76 | + |
77 | 77 | Email email = TestHelper.createBasicEmail(true); |
78 | | - |
| 78 | + |
79 | 79 | assertEquals(email.subject, TestHelper.subject); |
80 | 80 | assertEquals(email.html, TestHelper.html); |
81 | 81 | assertEquals(email.text, TestHelper.text); |
82 | 82 | } |
83 | | - |
84 | | - |
| 83 | + |
| 84 | + |
85 | 85 | /** |
86 | 86 | * Tests the email personalization |
87 | 87 | */ |
88 | 88 | @Test |
89 | 89 | public void TestEmailPersonalization() { |
90 | | - |
| 90 | + |
91 | 91 | String personalizationName = "test_personalization"; |
92 | 92 | String personalizationValue = "test_personalization_value"; |
93 | | - |
| 93 | + |
94 | 94 | Email email = new Email(); |
95 | | - |
| 95 | + |
96 | 96 | Recipient recipient = new Recipient(TestHelper.toName, TestHelper.toEmail); |
97 | | - |
| 97 | + |
98 | 98 | email.addPersonalization(recipient, personalizationName, personalizationValue); |
99 | | - |
| 99 | + |
100 | 100 | assertEquals(email.personalization.size(), 1); |
101 | | - |
| 101 | + |
102 | 102 | Personalization p = email.personalization.get(0); |
103 | | - |
| 103 | + |
104 | 104 | assertEquals(p.email, recipient.email); |
105 | | - |
| 105 | + |
106 | 106 | assertEquals(p.data.size(), 1); |
107 | | - |
| 107 | + |
108 | 108 | assertEquals(p.data.get(personalizationName), personalizationValue); |
109 | | - |
110 | | - |
| 109 | + |
| 110 | + |
111 | 111 | // add another personalization and test it too |
112 | 112 | String secondPName = "test_personalization_2"; |
113 | 113 | String secondPValue = "test_personalization_value_2"; |
114 | | - |
| 114 | + |
115 | 115 | email.addPersonalization(recipient, secondPName, secondPValue); |
116 | | - |
| 116 | + |
117 | 117 | assertEquals(email.personalization.size(), 1); |
118 | | - |
| 118 | + |
119 | 119 | Personalization p2 = email.personalization.get(0); |
120 | | - |
| 120 | + |
121 | 121 | assertEquals(p2.email, recipient.email); |
122 | | - |
| 122 | + |
123 | 123 | assertEquals(p2.data.size(), 2); |
124 | | - |
| 124 | + |
125 | 125 | assertEquals(p2.data.get(secondPName), secondPValue); |
126 | 126 | } |
127 | | - |
128 | | - |
| 127 | + |
| 128 | + |
129 | 129 | /** |
130 | 130 | * Tests that different recipients can have different personalization |
131 | 131 | */ |
132 | 132 | @Test |
133 | 133 | public void TestMultipleRecipientsPersonalization() { |
134 | | - |
| 134 | + |
135 | 135 | String personalizationName = "test_personalization"; |
136 | 136 | String personalizationValue = "test_personalization_value"; |
137 | | - |
| 137 | + |
138 | 138 | String secondPName = "test_personalization_2"; |
139 | 139 | String secondPValue = "test_personalization_value_2"; |
140 | | - |
| 140 | + |
141 | 141 | String recipient2Name = "Test recipient 2 name"; |
142 | 142 | String recipient2Email = "Test recipient 2 email"; |
143 | | - |
| 143 | + |
144 | 144 | Email email = new Email(); |
145 | | - |
| 145 | + |
146 | 146 | Recipient firstRecipient = new Recipient(TestHelper.toName, TestHelper.toEmail); |
147 | 147 | email.AddRecipient(firstRecipient); |
148 | | - |
| 148 | + |
149 | 149 | Recipient secondRecipient = new Recipient(recipient2Name, recipient2Email); |
150 | 150 | email.AddRecipient(secondRecipient); |
151 | | - |
| 151 | + |
152 | 152 | email.addPersonalization(firstRecipient, personalizationName, personalizationValue); |
153 | 153 | email.addPersonalization(secondRecipient, secondPName, secondPValue); |
154 | | - |
| 154 | + |
155 | 155 | assertEquals(email.personalization.size(), 2); |
156 | | - |
| 156 | + |
157 | 157 | Personalization p1 = email.personalization.get(0); |
158 | | - |
| 158 | + |
159 | 159 | assertEquals(p1.email, firstRecipient.email); |
160 | 160 | assertEquals(p1.data.size(), 1); |
161 | 161 | assertEquals(p1.data.get(personalizationName), personalizationValue); |
162 | | - |
| 162 | + |
163 | 163 | Personalization p2 = email.personalization.get(1); |
164 | | - |
| 164 | + |
165 | 165 | assertEquals(p2.email, secondRecipient.email); |
166 | 166 | assertEquals(p2.data.size(), 1); |
167 | 167 | assertEquals(p2.data.get(secondPName), secondPValue); |
168 | 168 | } |
169 | | - |
170 | | - |
| 169 | + |
| 170 | + |
171 | 171 | /** |
172 | 172 | * Tests that carbon copy recipients can be added to the email |
173 | 173 | */ |
174 | 174 | @Test |
175 | 175 | public void TestCcRecipients() { |
176 | | - |
| 176 | + |
177 | 177 | Recipient ccRecipient1 = new Recipient("name1", "test1@cc.com"); |
178 | 178 | Recipient ccRecipient2 = new Recipient("name2", "test2@cc.com"); |
179 | | - |
| 179 | + |
180 | 180 | Email email = TestHelper.createBasicEmail(false); |
181 | | - |
| 181 | + |
182 | 182 | // test adding the recipient directly |
183 | 183 | email.AddCc(ccRecipient1.name, ccRecipient1.email); |
184 | | - |
| 184 | + |
185 | 185 | assertEquals(email.cc.size(), 1); |
186 | | - |
| 186 | + |
187 | 187 | assertTrue(email.cc.get(0).name.equals(ccRecipient1.name)); |
188 | 188 | assertTrue(email.cc.get(0).email.equals(ccRecipient1.email)); |
189 | | - |
| 189 | + |
190 | 190 | // test adding the recipient object |
191 | 191 | email.AddCc(ccRecipient2); |
192 | | - |
| 192 | + |
193 | 193 | assertEquals(email.cc.size(), 2); |
194 | | - |
| 194 | + |
195 | 195 | assertTrue(email.cc.get(1).name.equals(ccRecipient2.name)); |
196 | 196 | assertTrue(email.cc.get(1).email.equals(ccRecipient2.email)); |
197 | 197 | } |
198 | | - |
199 | | - |
| 198 | + |
| 199 | + |
200 | 200 | /** |
201 | 201 | * Tests that blind carbon copy recipients can be added to the email |
202 | 202 | */ |
203 | 203 | @Test |
204 | 204 | public void TestBccRecipients() { |
205 | | - |
| 205 | + |
206 | 206 | Recipient bccRecipient1 = new Recipient("name1", "test1@bcc.com"); |
207 | 207 | Recipient bccRecipient2 = new Recipient("name2", "test2@bcc.com"); |
208 | | - |
| 208 | + |
209 | 209 | Email email = TestHelper.createBasicEmail(false); |
210 | | - |
| 210 | + |
211 | 211 | // test adding the recipient directly |
212 | 212 | email.AddBcc(bccRecipient1.name, bccRecipient1.email); |
213 | | - |
| 213 | + |
214 | 214 | assertEquals(email.bcc.size(), 1); |
215 | | - |
| 215 | + |
216 | 216 | assertTrue(email.bcc.get(0).name.equals(bccRecipient1.name)); |
217 | 217 | assertTrue(email.bcc.get(0).email.equals(bccRecipient1.email)); |
218 | | - |
| 218 | + |
219 | 219 | // test adding the recipient object |
220 | 220 | email.AddBcc(bccRecipient2); |
221 | | - |
| 221 | + |
222 | 222 | assertEquals(email.bcc.size(), 2); |
223 | | - |
| 223 | + |
224 | 224 | assertTrue(email.bcc.get(1).name.equals(bccRecipient2.name)); |
225 | 225 | assertTrue(email.bcc.get(1).email.equals(bccRecipient2.email)); |
226 | 226 | } |
|
0 commit comments