Question

Seems that PagedResultList is changed in grails 2.2.4 which is causing some issues in unit test.

The constructor is changed from

PagedResultList(list())

to

PagedResultList(GrailsHibernateTemplate template, Criteria crit) 
Was it helpful?

Solution

How about something like this...

def mockC = mockFor(org.hibernate.Criteria) 
mockC.demand.list { return []} //PagedResultList constructor calls this
def pagedList = new PagedResultList(null, mockC.createMock()){
    {
       //Using a static block to set private variables 
       //since we can't call a constructor here!
       list = yourList
       totalCount = yourList.size()
    }
}

OTHER TIPS

If only care about return values, attach totalCount to ArrayList.

def list = [domainObj1, domainObj2]
list.metaClass.getTotalCount {
    2
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top