想象一下,我有一个 EasyMock 测试,其中有以下几行:
final IRunControl runControl = createMock(IRunControl.class);
runControl.setSomething(isA(ISomething.class));
EasyMock.expectLastCall().once();
ISomething
看起来像这样:
interface ISomething
{
int getValue1();
String getValue2();
}
是否可以让 runControl.setSomething(isA(ISomething.class))
检查属性值?
我。 e.做类似的事情
runControl.setSomething(
and(
isA(ISomething.class),
and(propertyValue("value1", 123), propertyValue("value2", "expectedValue2")))
最佳答案
你需要的是使用Capture .
一个例子:
// 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());
关于java - 检查 EasyMock 匹配器中的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26120956/