We recently upgraded from Grails 2.4.4 to 2.5.1 and also to JDK 8. Ever since that, the below test case has been failing.
In our service class, we have a private method defined to call an external service.
def retrieveResults() {
def results = callSoapService('serviceName')
}
private def callSoapService(def serviceName) {
// call the service and format the results
}
And in my spock test:
def setup() {
service.metaClass.callSoapService = { String method -> mockSoapService(method) }
}
def "test service"() {
when:
def results = service.retrieveResults()
then:
some value == results.size()
}
private mockSoapService(String method) {
//mock the output
}
Basically over here, the private method is not getting mocked and the actual service is being called which is causing our test case to fail. Anybody has any pointers to mock a private method in Grails 2.5.1?