File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ import org.springframework.beans.SimpleTypeConverter
3737import org.springframework.mock.web.MockHttpSession
3838import org.springframework.validation.Errors
3939import org.springframework.web.context.request.RequestContextHolder
40+ import org.springframework.web.servlet.ModelAndView ;
41+
4042import grails.validation.ValidationException
4143
4244/**
@@ -103,7 +105,7 @@ class MockUtils {
103105 def renArgs = [:]
104106 def chaArgs = [:]
105107 def template = [:]
106- def modelAndView = [:]
108+ def modelAndView = new ModelAndView ()
107109 clazz. metaClass. getForwardArgs = {-> fwdArgs}
108110 clazz. metaClass. getRedirectArgs = {-> redArgs}
109111 clazz. metaClass. getRenderArgs = {-> renArgs}
@@ -227,6 +229,7 @@ class MockUtils {
227229
228230 clazz. metaClass. getTemplate = {-> template}
229231 clazz. metaClass. getModelAndView = {-> modelAndView}
232+ clazz. metaClass. setModelAndView = { ModelAndView mv -> modelAndView = mv}
230233 }
231234
232235 /**
Original file line number Diff line number Diff line change 11package grails.test ;
22
3+ import org.springframework.web.servlet.ModelAndView ;
4+
35/**
46 * Test case for {@link ControllerUnitTestCase}.
57 */
@@ -25,9 +27,22 @@ class ControllerUnitTestCaseTests extends GroovyTestCase {
2527 testCase. testCommandObject()
2628 testCase. tearDown()
2729 }
30+
31+ void testGetSetModelAndView () {
32+ def testCase = new UnitTestControllerTestCase ()
33+ testCase. setUp()
34+ testCase. testModelAndView()
35+ testCase. tearDown()
36+
37+ }
2838}
2939
3040class UnitTestControllerTestCase extends ControllerUnitTestCase {
41+
42+ void testModelAndView () {
43+ controller. testSetModelAndView()
44+ }
45+
3146 void testControllerClass () {
3247 assertEquals UnitTestController , controllerClass
3348 assertEquals " unitTest" , controller. controllerName
@@ -74,6 +89,11 @@ class UnitTestController {
7489 def index = {
7590
7691 }
92+
93+ def testSetModelAndView () {
94+ modelAndView = new ModelAndView ()
95+ println modelAndView. viewName
96+ }
7797}
7898
7999class ControllerUnitTestCaseCommandObject {
You can’t perform that action at this time.
0 commit comments