Can you try something like below in your controller test.
Domain.metaClass.beforeInsert = {-> }
PS: I have not tried this
If possible please paste you unit test code as well.
Question
I am testing a controller in Grails. It is using a model which has this method:
def beforeInsert() {
if (password != null) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
When I try to test a method that saves the password to the database it returns this message: java.lang.NullPointerException: Cannot invoke method encodePassword() on null object
How do I tell the test to just mock that method call or ignore that method call?
Solution
Can you try something like below in your controller test.
Domain.metaClass.beforeInsert = {-> }
PS: I have not tried this
If possible please paste you unit test code as well.
OTHER TIPS
You need to inject the springSecurityService in the controller itself.
def springSecurityService
controller.springSecurityService = springSecurityService