Domanda

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) 
È stato utile?

Soluzione

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()
    }
}

Altri suggerimenti

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

def list = [domainObj1, domainObj2]
list.metaClass.getTotalCount {
    2
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top