forked from dmurvihill/courier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailspec.scala
40 lines (33 loc) · 1.21 KB
/
mailspec.scala
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
package courier
import java.util.Properties
import javax.mail.Provider
import org.jvnet.mock_javamail.{Mailbox, MockTransport}
import org.scalatest._
import wordspec._
import matchers._
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
class MockedSMTPProvider extends Provider(Provider.Type.TRANSPORT, "mocked", classOf[MockTransport].getName, "Mock", null)
class MailSpec extends AnyWordSpec with should.Matchers {
private val mockedSession = javax.mail.Session.getDefaultInstance(new Properties() {{
put("mail.transport.protocol.rfc822", "mocked")
}})
mockedSession.setProvider(new MockedSMTPProvider)
"the mailer" should {
"send an email" in {
val mailer = Mailer(mockedSession)
val future = mailer(Envelope.from("[email protected]".addr)
.to("[email protected]".addr)
.cc("[email protected]".addr)
.subject("miss you")
.content(Text("hi mom")))
Await.ready(future, 5.seconds)
val momsInbox = Mailbox.get("[email protected]")
momsInbox.size === 1
val momsMsg = momsInbox.get(0)
momsMsg.getContent === "hi mom"
momsMsg.getSubject === "miss you"
}
}
}