Reputation: 15770
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?
Upvotes: 1
Views: 1002
Reputation: 123920
mockDao.persist(_) >> { it[0] }
Or, with destructuring:
mockDao.persist(_) >> { Entity entity -> entity }
Upvotes: 5