Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockito - Verify recursive methods

I have a method, which is recursive:

For example,

public static int myMethod(int index, int number) {
    if (index<4){
        index = index + number;
        return myMethod(index, number+1);
    }
    return index;
}

Now this is just a basic example. When I now want to test, how can I verify with Mockito, how many times the method gets called, because the parameters change?

Verify (myMethod(1,2)).times(3) would not work, because it only gets called once, then 1,2 will change.

like image 726
user5417542 Avatar asked Apr 23 '26 08:04

user5417542


1 Answers

This could help but won't verify if the method was invoked with correct arguments:

Mockito.verify(myMethod(Mockito.anyInt(), Mockito.anyInt()), Mockito.times(3));
like image 110
Dominik Kunicki Avatar answered Apr 24 '26 22:04

Dominik Kunicki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!