使用mockito验证对象属性值 [英] Verify object attribute value with mockito
问题描述
我有一个方法调用,我想用mockito模拟。首先,我创建并注入了一个将在其上调用方法的对象实例。我的目的是验证方法调用中的一个对象。
I have a method call which I want to mock with mockito. To start with I have created and injected an instance of an object on which the method will be called. My aim is to verify one of the object in method call.
有没有一种方法,当mock方法是mockito时,mockito允许你断言或验证对象及其属性叫?
Is there a way that mockito allows you to assert or verify the object and it's attributes when the mock method is called?
示例
Mockito.verify(mockedObject)
.someMethodOnMockedObject(
Mockito.<SomeObjectAsArgument>anyObject())
而不是做 anyObject()
我想检查参数对象是否包含某些特定字段
Instead of doing anyObject()
i want to check that argument object contains some particular fields
Mockito.verify(mockedObject)
.someMethodOnMockedObject(
Mockito.<SomeObjectAsArgument>**compareWithThisObject()**)
推荐答案
http://sites.google.com/a/pintailconsultingllc.com/java/argument-matching-with-mockito
此链接提供了一个工作示例。我能够用相同的策略解决它。
This link provides a working example. I was able to solve it with same strategy.
这篇关于使用mockito验证对象属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!