-1

I was trying to mock a final static void method inside a final class. I want to return some values using the arguments in my final method. I am using powermockito. can anyone tell me how we can mock a final static void method and return some value as I mentioned above.

final class

public final class myFinalClass{

   public final static void myMethod(String s, String val) {

   }
}

1 Answers1

0

PowerMockito can be used for both mocking and verifying static methods.

How to Mock:

PowerMockito.mockStatic(ClassWithStaticMethods.class) 
PowerMockito.when(ClassWithStaticMethods.staticMethodCall()).thenReturn (obj1);

How to verify:

PowerMockotio.verifystatic(Mockito.times(1));
ClassWithStaticMethods.staticMethodCall();
Pranalee
  • 3,389
  • 3
  • 22
  • 36