I'm very new in spock framework testing and I didn't find any example where I can find needed information. Therefore, I think the best way is to show an example what I need to have.
e.g. test class in spock:
def "getData" (){ // this is test of getData method from ExternalService when: Result result = externalService.getData() then: result.msg = 'SUCCESS' }Service Class:
public class ExternalService(){ private ServiceConnector serviceConnector; public Result getData(){ Result result = serviceConnector.callAndGet(); prepareInformation(data); updateStatuses(data); return result; } }Class Data as a Domain Class:
public class Data { private String msg private int Id // +getters/setters }
And now I have getData test and would like to mock the only method callAndGet(). It means every time I call callAndGet I need to have object Data with msg SUCCESS but all other methods from getData method should be called normally.
Is it quite understandable? The question is how can we inject/mock the service class ExternalService into the spock test class?