[英]How to mock case class?
I have following case class: 我有以下案例课:
case class User(username:String, createdDate:DateTime)
and a class to test: 和一个要测试的课程:
class UserDAO{
def registerUser(user:User)
}
I want to verify that registerUser
called with an input user that has username="myusername"
. 我想验证
registerUser
调用具有输入用户username="myusername"
。 Based on this docs https://mockito.googlecode.com/hg-history/1.7/javadoc/org/mockito/Matchers.html I came up with a code like this: 基于此文档https://mockito.googlecode.com/hg-history/1.7/javadoc/org/mockito/Matchers.html我想到了这样的代码:
verify(userDAO).registerUser(User(eq("myusername"),any[DateTime]))
however it is not right and I had error while compiling. 但是这是不对的,我在编译时出错。
Error is Type mismatch, expected UUID actual Boolean
错误是
Type mismatch, expected UUID actual Boolean
I solved my problem by using a different approach. 我通过使用其他方法解决了我的问题。 I used
capture
the input argument of a mocked object and then validate the captured value. 我使用了
capture
模拟对象的输入参数,然后验证捕获的值。
http://docs.mockito.googlecode.com/hg/org/mockito/ArgumentCaptor.html http://docs.mockito.googlecode.com/hg/org/mockito/ArgumentCaptor.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.