如何验证是否已调用 MailerAPI.send 的 ScalaMocks 存根



如何验证是否已调用play.api.libs.mailer.MailerAPI的 ScalaMock 存根的send(Email)方法?

class SomeTests extends FunSuite with MockFactory {
  [...]
  val expEmail = play.api.libs.mailer.Email(
    "Test",
    "admin@test.com",
    Seq("user@test.com"),
    bodyHtml = Some(s"""<html>
        | <body>
        |   Hello
        | </body>
        | </html>
        | """.stripMargin)
  )
  val mailerFake = stub[MailerAPI]
  // Won't compile
  (mailerFake.send _).verify(expEmail)
  [...]
}

编译上述代码时,出现以下错误:

Error:(29, -1) Play 2 Compiler: 
 /Users/arve/Projects/gradlehub/test/ui/pub/RegistrationTest.scala:29: ambiguous reference to overloaded definition,
 both method send in trait MailerAPI of type (data: play.libs.mailer.Email)String
 and  method send in trait MailerAPI of type (data: play.api.libs.mailer.Email)String

由于编译错误已经说明了send是重载的,因此您需要一种方法来消除歧义,您可以通过显式声明所需的send类型来消除歧义:

(mailerFake.send: (play.api.libs.mailer.Email => String)).verify(expEmail)

相关内容

  • 没有找到相关文章

最新更新