Reputation: 602
I am writing a unit test for a grails controller. Here is a snippet of the code:
@TestFor(MyController)
@Mock([MyDomain])
class MyControllerTests {
void testController() {
...
...
}
}
Here is how the domain object looks like:
class MyDomain {
static constraints = {
name(nullable: false)
parent(nullable: true)
}
static belongsTo = Industry
static hasMany = [children: Industry]
Industry parent
String name
}
The method in the controller I am testing calls this GORM dynamic method:
MyDomain.listOrderByParent()
The test fails when execution hits this line and the exception is not making much sense to me since the @Mock annotation should have added all the dynamic methods:
groovy.lang.GroovyRuntimeException: Cannot compare com.stuff.MyDomain with value 'com.stuff.MyDomain : 1' and com.stuff.MyDomain with value 'com.stuff.MyDomain : 4'
at org.grails.datastore.mapping.simple.query.SimpleMapQuery$_executeQuery_closure63_closure155.doCall(SimpleMapQuery.groovy:78)
The controller works fine when running the grails app. Any ideas?
Upvotes: 1
Views: 582
Reputation: 4714
You may mock the Industry domain object as well:
@Mock([MyDomain, Industry])
Upvotes: 0