1

似乎 PagedResultList 在 grails 2.2.4 中发生了更改,这导致了单元测试中的一些问题。

构造函数从

PagedResultList(list())

PagedResultList(GrailsHibernateTemplate template, Criteria crit) 
4

2 回答 2

3

像这样的东西怎么样...

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()
    }
}
于 2013-10-07T04:11:59.283 回答
2

如果只关心返回值,请附加totalCountArrayList.

def list = [domainObj1, domainObj2]
list.metaClass.getTotalCount {
    2
}
于 2014-05-11T08:30:31.570 回答