How to test the number of times a static method in Java is called?

Viewed 2831

I have a class with methodA() that eventually calls a static methodB() that returns a String. methodA() can cause multiple invocations of methodB(), depending on the scenario.

I want to write a unit test to verify that a single invocation of methodA() will only result in a single invocation methodB().

How can this be done? I looked at PowerMockito but wasn't able to find suitable examples.

class classA {
   public int methodA() {
      // Do something that invokes a method that in turn calls B.methodB()
   }
}

class classB {
   public static String methodB(String str) {
      // Do something
   }
}
1 Answers
Related