lundi 26 janvier 2015

During testing, how can I fake MailerPlugin.send so I can get the sent email?

During testing I wish to fake play.api.libs.mailer.MailerPlugin in Play 2.3, so that I can get hold of the email being sent. How do I do this?


App Code



package services
import play.api.libs.mailer._
import play.api.Play.current

object EmailService {
def sendUserNotification(to: String, subject: String, content: String): Unit = {
val email = Email(
"subject",
"Admin <admin@test.com>",
Seq(to),
bodyHtml = Some(s"""<html>
| <body>
| $content
| </body>
| </html>
| """.stripMargin)
)
// Should like to fake this from tests, but how?
MailerPlugin.send(email)
}
}


Test Code



object Test {
def testEmail(): Unit = {
// How do I get hold of the sent email?
EmailService.sendUserNotification("user@user.com", "Test", "Testing...")
}
}

Aucun commentaire:

Enregistrer un commentaire