Skip to content

Instantly share code, notes, and snippets.

@michaelrice
Created January 22, 2015 15:26
Show Gist options
  • Select an option

  • Save michaelrice/5bb0da6c8a17a85724a3 to your computer and use it in GitHub Desktop.

Select an option

Save michaelrice/5bb0da6c8a17a85724a3 to your computer and use it in GitHub Desktop.
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()
}
}
@michaelrice
Copy link
Copy Markdown
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment