问题描述
我的应用程序代码使用AService
My application code uses AService
trait AService {
def registerNewUser (username: String)(implicit tenant: Tenant): Future[Response]
}
注册一个新用户.租户类是一个简单的案例类:
to register a new user. Class Tenant is a simple case class:
case class Tenant(val vstNumber:String, val divisionNumber:String)
特质AServiceMock通过模拟AService的版本来模仿注册逻辑
Trait AServiceMock mimics the registration logic by using a mocked version of AService
trait AServiceMock {
def registrationService = {
val service = mock[AService]
service.registerNewUser(anyString) returns Future(fixedResponse)
service
}
}
现在,每当在AService上调用registerNewUser时,响应将为"fixedResponse"(在其他地方定义).
Iow whenever registerNewUser is called on AService the response will be "fixedResponse" (defined elsewhere).
我的问题是,如何将隐式租户参数定义为类似于anyString的模拟匹配器?
My question is, how do I define the implicit tenant-parameter as a mockito matcher like anyString?
顺便说一句.我正在将Mockito与Specs2(和Play2)配合使用
btw. I'm using Mockito with Specs2 (and Play2)
推荐答案
有时您必须先在SO上发布,才能得出完全显而易见的答案(duhh):
Sometimes you have to post on SO first to come up with the completely obvious answer (duhh):
service.registerNewUser(anyString)(any[Tenant]) returns Future(fixedResponse)
这篇关于如何在Mockito和Scala中使用隐式匹配器对方法调用进行存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!