Reputation: 366
I am trying to mock Static methods using PowerMockito. It works fine when I try To mock only one Class. For instance Class1.staticMethod(). But my tested class uses other static method from other class Class2.staticMethod().
So my question is: How to mock two different static methods from different classes, in the same test using PowerMockito?
I can not use mockito-inline
dependency, so it should be done only with PowerMockito.
Upvotes: 0
Views: 52
Reputation: 533
If you simply provide two static mocks you can control the behavior of each method.
I usually do something like this in Mockito:
protected static MockedStatic<Class1> CLASS1_MOCK= Mockito.mockStatic(Class1.class);
CLASS1_MOCK.when(Class1::staticMethod).thenReturn(testValue1);
protected static MockedStatic<Class2> CLASS2_MOCK = Mockito.mockStatic(Class2.class);
CLASS2_MOCK.when(Class2::staticMethod).thenReturn(testValue2);
Upvotes: 1