I can mock calls to:
MyDomainClass.createCriteria().list{
eq('id',id)
eq('anotherParameter',anotherParameterId)
}
with:
def myCriteria = [
list : {Closure cls -> returnThisObject}
]
MyDomainClass.metaClass.static.createCriteria = { myCriteria }
as advised at:
http://davistechyinfo.blogspot.com/2010/01/mocking-hibernate-criteria-in-grails.html
but for:
MyDomainClass.createCriteria().get{
eq('id',id)
eq('anotherParameter',anotherParameterId)
}
This approach fails - maybe because 'get' is a keyword in a way 'list' is not. Can anyone advise - being able to mock this in domain classes should be possible, without simply abandoning unit test coverage for methods that use createCriteria().get{}
.
Suggestions much appreciated,
Alex