PagedResultList Instance in Grails 3.1.7 Unit Test -
is possible create pagedresultlist instance or mock?
for background: i´m writing controller unit tests. if necessary stubbing service function calls. of functions have pagedresultlist
return type. have inject pagedresultlist
instance or null
.
in cases need instance because controller this:
testfunction(){ def result = sampleservice.dosomething() if (result.empty) { variable = "it´s empty" } render variable }
my test looking 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 me replace ?????
pice of code fix issue?
thanks in advance.
yes, there couple options here:
- you use real pagedresultlist
emptypagedresultlist
- see foocontrollerspec.groovy line 11 example - you use spock
mock()
emptypagedresultlist
- see foocontrollerspec.groovy line 25 example
Comments
Post a Comment