Grails controller unit test - injected object is null

17 Views Asked by At

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?

0

There are 0 best solutions below