Skip to content

Commit c94c133

Browse files
committed
fix for GRAILS-9718 "NullPointerException in Grails unit tests because of null Params and Session"
1 parent efe9112 commit c94c133

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

grails-plugin-testing/src/main/groovy/grails/test/mixin/web/GroovyPageUnitTestMixin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.codehaus.groovy.grails.commons.GrailsTagLibClass
2323
import org.codehaus.groovy.grails.commons.TagLibArtefactHandler
2424
import org.codehaus.groovy.grails.commons.metaclass.MetaClassEnhancer
2525
import org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi
26+
import org.codehaus.groovy.grails.web.pages.GroovyPageRequestBinding
2627
import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
2728
import org.codehaus.groovy.grails.web.pages.TagLibraryLookup
2829
import org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils;
@@ -60,7 +61,7 @@ class GroovyPageUnitTestMixin extends ControllerUnitTestMixin {
6061
@Before
6162
void bindGrailsWebRequest() {
6263
super.bindGrailsWebRequest()
63-
pageScope = new GroovyPageBinding()
64+
pageScope = new GroovyPageBinding(new GroovyPageRequestBinding(webRequest))
6465
request.setAttribute(GrailsApplicationAttributes.PAGE_SCOPE, pageScope)
6566

6667
}

grails-test-suite-uber/src/test/groovy/grails/test/mixin/ControllerAndGroovyPageMixinTests.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ import org.junit.Test
1010
@TestFor(MyController)
1111
class ControllerAndGroovyPageMixinTests {
1212

13-
// verifies the above 2 mixins can operator together without error
13+
// GRAILS-9718
1414
@Test
1515
void testController() {
1616
controller != null
17+
18+
views['/foo/_bar.gsp'] = 'Id: ${params.id}'
19+
20+
params.id = 10
21+
def content = render(template:"/foo/bar")
22+
23+
assert content == 'Id: 10'
1724
}
1825
}

0 commit comments

Comments
 (0)