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

时间:2015-01-26 15:30:51

标签: scala playframework scalatest scalamock

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

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

1 个答案:

答案 0 :(得分:4)

由于编译错误已经说明send已重载,因此您需要一种消除歧义的方法,您可以通过明确说明所需的send类型来解决问题:

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