I'm using Spock to test a grails controller. In the controller:
def submitUserRegistration() {
loginService.sudoAsAppAdmin { // sudoAsAppAdmin is a method that accepts a closure
In the test:
LoginService loginService = Mock()
loginService.sudoAsAppAdmin(_) >> { args -> args[0].call() }
controller.loginService = loginService
// other setup
controller.submitUserRegistration() == null
Result:
java.lang.NullPointerException: Cannot invoke method sudoAsAppAdmin() on null object
I can't post the whole project or probably even the whole controller. Any idea what I can try to fix this?