Facing similar issue to the question asked in another thread Null Pointer Exception in Unit test in spock
I have a java class and method that accepts Map (java.util.Map) and returns MyEntity as shown below.
@Service
public class MyService {
     public MyEntity process(Map requestMap) {
          MyEntity retObj = new MyEntity();
          // ...
          return retObj;
     }
}
And I am writing unit test for this method call in Spock like below
class mySpec extends Specification {
    MyService service
    void setup() {
        // ...
        service = new MyService()
        // ...
    }
     def "call process with request map"(){
        given:
        Map requestMap = [
            id : 'd21f7479-8fd0-46c1-b612-1375f3fa3289',
            tenantId : '507f191e810c19729de860ea'
        ] 
        // ... mockObject from repo (not shown for the sake of brevity) 
        when:
        MyEntity foundObject = service.process(requestMap) // Here is where NPE occurs
        then:
        foundObject.getId() == mockObject.getId()
    }
}
The Null pointer exception occurs during when: block
MyEntity foundObject = service.process(requestMap)
Could anyone suggest where I might be going wrong?
 
    