In my controller I have code like the following.RedisTemplate stringRedisTemplate
def accessRedis(){ val = stringRedisTemplate.opsForValue().get('Key')}
In my controller Test, I intent to inject a mocked RedisTemplate that return a mocked ValueOperations. My code:
def template = mockFor(RedisTemplate) def val = mockFor(org.springframework.data.redis.core.ValueOperations)val.demand.get {p-> println "$p"}template.demand.opsForValue { return val.createMock()}controller.stringRedisTemplate = template.createMock()controller.accessRedis()
However, I got the following error:org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.tnd.viewport.ui.AppHawkControllerSpec$_$spock_feature_0_1_closure2@1aa55dd5' with class 'com.tnd.viewport.ui.AppHawkControllerSpec$_$spock_feature_0_1_closure2' to class 'org.springframework.data.redis.core.ValueOperations'
Could you advice a solution for my scenario? Thanks!