I am using micronaut framework and spock for writing test case of API.
I am trying to create testcase of my API which internally calls PaymentIntent.retrieve()
static method of 3rd party api.
I want to mock this 3rd party url call and return a fakeObject of PaymentIntent
instead.
Here is a sample test case that I created which is executing the actual 3rd party api static method:
@Inject Service myService;
@Unroll
void "method returns nothing"() {
given:
PaymentIntent paymentIntent = new PaymentIntent()
Mock(PaymentIntent)
PaymentIntent.retrieve("pi_123", requestOptions) >> paymentIntent
when:
def result = myService.getPayment("", "pi_123", obj)
then:
result.amount == paymentIntent.amount
}
Can someone guide me around how can restrict the execution of the actual API?
I have refer these already asked questions but it is not worked in my case. Mock static method with GroovyMock or similar in Spock