In Mockito there is nice method for programatic answers from interactions with mocks. E.g. we can program mock to return parameter which was passed to it’s method call:
when(mockDao.persist(any(Entity.class)).thenAnswer(new Answer<Entity>() {
public Entity answer(InvocationOnMock invocationOnMock) throws Throwable {
Entity entity = (Entity) invocationOnMock.getArguments()[0];
return entity;
}
});
Is there a way to do the same in Spock?
Or, with destructuring: