1

In my service, the grailsApplication instance is auto injected and it is used to look up the domain name as follows:

grailsApplication.getDomainClass(domain.getClass().name)?.clazz

How to mock this in the unit test. So far, i have been doing something like:

def getDomainClass = {
                assert null
            }
def grailsApplication  = [getDomainClass: getDomainClass]
service.grailsApplication = {grailsApplication as GrailsApplication}

However, this doesn't work. It appears, we are getting following error:

interface org.springframework.validation.Errors

Any suggestions how to mock it? Thank You

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
latvian
  • 3,161
  • 9
  • 33
  • 62
  • 1
    Which version of Grails are you using? For Grails 2.0 and above you can use `@TestFor` which mocks `grailsApplication` for you. Refer [this question](http://stackoverflow.com/questions/13845975/grailsapplication-access-in-grails-unit-test) for details. – dmahapatro Jun 05 '13 at 16:58
  • Thank you dmahaptro. It is 2.1.2 and you right. It is mocked. Thank You – latvian Jun 05 '13 at 18:19

0 Answers0