@Mock fails if domain class has property named 'list'
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
Following exception is thrown if we try to mock domain with property named 'list' if constraint is defined for it. Changing property name resolves issue. There is single domain and unit spec for it in project under: https://github.com/droggo/bugs/tree/master/DomainPropertyNameListBug
Appeared after migrating to grails 2.5.2 from 2.4.2
```
class DomainWithListPropertyName {
String list
static constraints = {
list nullable: true
}
}
```
```
@Mock(DomainWithListPropertyName)
class DomainWithListPropertyNameSpec extends Specification {
void 'ensure domain may be saved'(){
expect:
new DomainWithListPropertyName().save(failOnError: true)
}
}
```
```
ensure domain may be saved(grails.DomainWithListPropertyNameSpec)
|
java.lang.IllegalStateException: Method on class [grails.DomainWithListPropertyName] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
at grails.DomainWithListPropertyName._clinit__closure1(DomainWithListPropertyName.groovy:12)
at org.grails.datastore.mapping.config.groovy.MappingConfigurationBuilder.evaluate(MappingConfigurationBuilder.groovy:83)
at org.grails.datastore.mapping.config.AbstractGormMappingFactory.createMappedForm(AbstractGormMappingFactory.java:63)
at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:39)
at org.grails.datastore.mapping.keyvalue.mapping.config.GormKeyValueMappingFactory.createMappedForm(GormKeyValueMappingFactory.java:28)
at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.(KeyValuePersistentEntity.java:35)
at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext.createPersistentEntity(KeyValueMappingContext.java:95)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntities(AbstractMappingContext.java:174)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomains(DomainClassUnitTestMixin.groovy:86)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:153)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$1$2.evaluate(TestRuntimeJunitAdapter.groovy:49)
at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$3$4.evaluate(TestRuntimeJunitAdapter.groovy:76)
at org.spockframework.runtime.extension.builtin.ClassRuleInterceptor.intercept(ClassRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
```
Contributor guide
Research direction
Start with the DomainPropertyNameListBug reproduction linked in the issue and the DomainClassUnitTestMixin.groovy stack-frame location. Trace how the list constraint is processed through the mapping configuration during @Mock setup. Done means the provided domain unit spec saves successfully without the IllegalStateException, with a regression test covering the list property and nullable constraint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100