In the integration test, i am using groovy mock feature to mock a service method like shown below:
def mock = new groovy.mock.interceptor.MockFor(PaymentService)
mock.demand.processPayment(){ a, b, c-> ['status': true, 'approved': true, 'tresponse': new TransactionResponse(amount: total.toBigDecimal(), transactionId: "4234234555", saleId: Sale.last().id, responseCode: "1", responseReasonCode: "1", responseReasonText: "approved", authorizationCode: "asdasd", paymentMethod: "CC", transactionType: "auth_capture", cardCodeResponse: "P").save(flush: true)]}
mock.use{
controller.paymentService = new PaymentService()
populateReceiptParams(total)
controller.receipt()
}
The payment controller method receipt() uses payment service method processPayment which communicates with authorize.net. So i have mocked out this method as shown above.
When the test is run, the error i am getting is as follows
junit.framework.AssertionFailedError: No call to 'getMergedSale' expected at this point. Still 1 call(s) to 'processPayment' expected.
at PaymentController.cart(PaymentController.groovy:296)
at PaymentController.receipt(PaymentController.groovy:1096)
So the thing is that inside receipt method there is another call to paymentservice being made
paymentService.getMergedSale([sessionAuth, userAuth])
So does this mean that the mocked method which is processPayment must be called first before getMergedSale? I appreciate any guide as to the reason for this error. Thanks!