Question

I have class with all the methods static and final. How do I mock a method which is both static and final in the class.

public class UtilityClass{
  public static final void utilityMethod(){
  }

  public static final Integer anotherUtilMethod(){
  }
}

How to mock utilMethod() and anotherUtilMethod() using PowerMock?

Was it helpful?

Solution

final UtilityClass util = PowerMockito.mock(UtilityClass.class);
PowerMockito.mockStatic(UtilityClass.class);

Then use PowerMockito.when() like you normally would. Look at http://code.google.com/p/powermock/wiki/MockitoUsage13 for examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top