How do you mock a final method using PowerMock?
A) mock() and when()
B) spy() and doReturn()
C) mockFinalMethod()
D) mockFinal()
Answer:
A) mock() and when()
Explanation:
To mock a final method using PowerMock, you can use the mock()
method in combination with when()
to define the behavior of the final method.
For example:
ClassWithFinalMethod mock = mock(ClassWithFinalMethod.class);
when(mock.finalMethod()).thenReturn("Mocked Value");
In this example, the final method finalMethod()
in the ClassWithFinalMethod
class is mocked using PowerMock.