I have a problem like this
public class ErrorLog {
public static void increment(String exception) {
// do something
}
}
import ErrorLog;
public class Calculator {
public int division(int a, int b) {
if (b == 0) {
ErrorLog.increment("Divide by Zero");
} else {
return a / b;
}
}
}
I want to verify the number of calls to divide, but when I have divide by zero situation, somehow verify that the static method ErrorLog.increment is called (with the exact string as the parameter).
With Mockito spy, I can do something like this to ensure calls to the divide method.
Calculator c = new Calculator();
Calculator calcSpy = spy(c);
c.division(6, 3);
c.division(1, 0);
verify(calcSpy, times(2)).division(anyInt(), anyInt());
I also keen to verify something like this
verify(ErrorLog, times(1)).increment("Divide by Zero");
I explored PowerMockito verifyStatic constructs and mockStatic, checked this one too mockito verify method call inside method but in my case the method that is called inside the object is static.