[英]Checking property values in an EasyMock matcher
Imagine, I have an EasyMock test, in which I have following lines: 想象一下,我有一个EasyMock测试,其中我有以下几行:
final IRunControl runControl = createMock(IRunControl.class);
runControl.setSomething(isA(ISomething.class));
EasyMock.expectLastCall().once();
ISomething
looks like this: ISomething
看起来像这样:
interface ISomething
{
int getValue1();
String getValue2();
}
Is it possible to make runControl.setSomething(isA(ISomething.class))
check the values of properies? 是否有可能使
runControl.setSomething(isA(ISomething.class))
检查属性的值?
I. e. I. e。 do something like
做点什么
runControl.setSomething(
and(
isA(ISomething.class),
and(propertyValue("value1", 123), propertyValue("value2", "expectedValue2")))
What you need is to use Capture . 你需要的是使用Capture 。
An example: 一个例子:
// setup: data
ISomething fooSomething = ISomethingImpl(5, "bar");
// setup: expectations
Capture<ISomething> capturedISomething = new Capture<ISomething>();
mockCollaborator.setSomething(capture(capturedISomething));
// exercise
replay(mockCollaborator);
sut.dooWhateverThatInvokesTheCollaboratorSetter(fooSomething);
// verify
verify(mockCollaborator);
assertEquals(5, capturedISomething.getValue().getValue1());
assertEquals("bar", capturedISomething.getValue().getValue2());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.