This question already has an answer here:
- Final method mocking 7 answers
I need to use a mock who has a final method. So i use powermock but it does not work
class B {
public final int nb() {
return 4;
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest(B.class)
public class Exemple extends TestCase {
@Test
public void test() {
B b = PowerMockito.mock(B.class);
PowerMockito.when(b.nb()).thenReturn(5);
final int actualState = b.nb();
assertEquals(5, actualState);
}
}
if someone has a solution, thank you in advance