似乎PagedResultList在grails 2.2.4中已更改,这在单元测试中引起了一些问题。

构造函数从

PagedResultList(list())


PagedResultList(GrailsHibernateTemplate template, Criteria crit)

最佳答案

这样的事情怎么样...

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

关于grails - 如何在Grails 2.2.4中模拟PagedResultList,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18909179/

10-13 05:33