se-jaeger
se-jaeger

Reputation: 111

PagedResultList Instance in Grails 3.1.7 Unit Test

Is it possible to create PagedResultList instance or Mock?

For Background: Currently I´m writing Controller Unit tests. If it is necessary I stubbing Service function calls. But some of this functions have PagedResultList as return type. So i have to inject a PagedResultList instance or null.

In some cases I need an instance because the controller do something like this:

testFunction(){
    def result = sampleService.doSomething()

    if (result.empty) {
        variable = "it´s empty"
    }
    render variable
}

My Test looking like this:

void "sample Test"(){
    given:
        controller.sampleService = Mock(SampleService)
        PagedResultList emptyPagedResultList = ?????

    when:
        controller.testFunction()

    then:
        1 * controller.sampleService.doSomething() >> emptyPagedResultList
        response.text == "it´s empty"
}

Someone can help me to replace the ????? with a pice of code to fix this issue?

Thanks in advance.

Upvotes: 0

Views: 247

Answers (1)

Colin Harrington
Colin Harrington

Reputation: 4459

Yes, there are a couple options here:

Upvotes: 4

Related Questions