/
AssertAllEmailTestSample.java
71 lines (62 loc) · 2.35 KB
/
AssertAllEmailTestSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package fr.sii.ogham.sample.test;
import static com.icegreen.greenmail.util.ServerSetupTest.SMTP;
import static fr.sii.ogham.testing.assertion.OghamAssertions.assertAll;
import static fr.sii.ogham.testing.assertion.OghamAssertions.assertThat;
import static fr.sii.ogham.testing.assertion.OghamMatchers.isSimilarHtml;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import com.icegreen.greenmail.junit4.GreenMailRule;
import fr.sii.ogham.core.builder.MessagingBuilder;
import fr.sii.ogham.core.exception.MessagingException;
import fr.sii.ogham.core.service.MessagingService;
import fr.sii.ogham.email.message.Email;
public class AssertAllEmailTestSample {
private MessagingService oghamService;
@Rule
public final GreenMailRule greenMail = new GreenMailRule(SMTP);
@Before
public void setUp() throws IOException {
oghamService = MessagingBuilder.standard()
.environment()
.properties()
.set("ogham.email.from.default-value", "Sender Name <test.sender@sii.fr>")
.set("mail.smtp.host", SMTP.getBindAddress())
.set("mail.smtp.port", String.valueOf(SMTP.getPort()))
.and()
.and()
.build();
}
@Test
public void simple() throws MessagingException, javax.mail.MessagingException {
// @formatter:off
oghamService.send(new Email()
.subject("Simple (assertAll)")
.body().string("<html><body>Hello world!</body></html>")
.to("Recipient Name <recipient@sii.fr>"));
assertAll(r -> // <1>
assertThat(greenMail, r).receivedMessages() // <2>
.count(is(1))
.message(0)
.subject(is("Simple (assertAll)"))
.from()
.address(hasItems("test.sender@sii.fr"))
.personal(hasItems("Sender Name")).and()
.to()
.address(hasItems("recipient@sii.fr"))
.personal(hasItems("Recipient Name")).and()
.body()
.contentAsString(isSimilarHtml("<html><body>Hello world!</body></html>"))
.contentType(startsWith("text/html")).and()
.alternative(nullValue())
.attachments(emptyIterable())
);
// @formatter:on
}
}