I want to mock final method of a class. I tried
PowerMockito.mock(mockedClass.class)
But it is not working for me. It is giving NullPointerException
. I am using TestNG to run my test cases.
I want to mock final method of a class. I tried
PowerMockito.mock(mockedClass.class)
But it is not working for me. It is giving NullPointerException
. I am using TestNG to run my test cases.
According to Mockito documentation on final types and methods here it is possible to enable mocking of final classes and final methods by use the following dependency mockito-inline
instead of mockito-core
. I tried to do that and succeeded in mocking both a final class and a final method even without PowerMockito
.
I used the following dependency
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>2.12.0</version>
<scope>test</scope>
</dependency>
and ran tests using JDK 8.
Perhaps that may help you.