Представьте, у меня есть тест 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))
проверить значения свойств?
I. 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());