def data = User.createCriteria().list(
offset:params.start,
max:params.limit,
sort:params.sort,
order:params.dir)
{
and {
eq("client", session.client)
}
}
And in gmock, I can mock like this in version 0.9:
def criteria = mock {
list(offset: ..., order: ..., invoke {
and(invoke {
eq('client', session.client)
})
}).returns(...)
}
mock(User).static.createCriteria().returns(criteria)
But it is not intuitive enough, and chained method calls are common in
groovy, so I have an immature new thought that support chained method
calls like:
mock(User).static.createCriteria().list(offset: ..., order: ..., invoke
{
and(invoke {
eq('client', ...)
})
}).returns(...)
Here when list() is called, a new mock is created. So this piece of code
is completely equal to the original one.
So, do you like it? :)