Created
January 22, 2015 15:26
-
-
Save michaelrice/5bb0da6c8a17a85724a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.test | |
| import grails.test.ControllerUnitTestCase | |
| import grails.test.mixin.* | |
| import org.junit.* | |
| /** | |
| * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions | |
| */ | |
| @TestFor(MyFancyThingController) | |
| @Mock(MyFancyThingService) | |
| class MyFancyThingControllerTests extends ControllerUnitTestCase { | |
| @Before | |
| void setUp() { | |
| def myService = mockFor(MyFancyThingService, true) | |
| controller.myFancyThingService = myService | |
| } | |
| void testSomething() { | |
| controller.myFancyThingService.serviceMethod() | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{serviceMethod=com.test.MyFancyThingControllerTests$_setUp_closure1@21febcbb}' with class 'java.util.LinkedHashMap' to class 'com.test.MyFancyThingService' due to: org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: serviceMethod for class: com.test.MyFancyThingService
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:358)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2398)
at groovy.lang.ExpandoMetaClass.setProperty(ExpandoMetaClass.java:1170)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3336)