diff --git a/build.sbt b/build.sbt index 7d75cd9..ab6adad 100644 --- a/build.sbt +++ b/build.sbt @@ -18,7 +18,7 @@ ThisBuild / organization := "app.softnetwork" name := "notification" -ThisBuild / version := "0.9.1" +ThisBuild / version := "0.9.2" ThisBuild / scalaVersion := scala212 diff --git a/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala b/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala index 384facd..c208d5c 100644 --- a/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala +++ b/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala @@ -132,6 +132,8 @@ trait NotificationTestKit[T <: Notification] private var smtpMockServer: Option[SmtpMockServer] = None + protected def receivedEmails: Seq[com.dumbster.smtp.SmtpMessage] = + smtpMockServer.map(_.received).getOrElse(Seq.empty) protected def initSmtpMockServer(coordinatedShutdown: Boolean): Unit = { val server = new SmtpMockServer with InternalConfig { lazy val log: Logger = LoggerFactory getLogger getClass.getName diff --git a/testkit/src/main/scala/app/softnetwork/notification/scalatest/SmtpMockServer.scala b/testkit/src/main/scala/app/softnetwork/notification/scalatest/SmtpMockServer.scala index b8a65be..f6ce565 100644 --- a/testkit/src/main/scala/app/softnetwork/notification/scalatest/SmtpMockServer.scala +++ b/testkit/src/main/scala/app/softnetwork/notification/scalatest/SmtpMockServer.scala @@ -4,9 +4,10 @@ import akka.Done import akka.actor.typed.ActorSystem import app.softnetwork.api.server.scalatest.MockServer import app.softnetwork.notification.config.{InternalConfig, MailSettings} -import com.dumbster.smtp.SimpleSmtpServer +import com.dumbster.smtp.{SimpleSmtpServer, SmtpMessage} import scala.concurrent.Future +import scala.jdk.CollectionConverters._ import scala.util.{Failure, Success, Try} trait SmtpMockServer extends MockServer with MailSettings { @@ -40,4 +41,8 @@ trait SmtpMockServer extends MockServer with MailSettings { } Future.successful(Done) } + + /** Mails received by this mock SMTP server since startup. */ + def received: Seq[SmtpMessage] = + maybeServer.map(_.getReceivedEmails.asScala.toSeq).getOrElse(Seq.empty) }