質問

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) 
役に立ちましたか?

解決

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

他のヒント

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

def list = [domainObj1, domainObj2]
list.metaClass.getTotalCount {
    2
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top