June 2014
Intermediate to advanced
284 pages
6h 9m
English
In this recipe, we will stub a final method and verify the object under test's behavior using JUnit. Since Mockito can't stub final methods, we'll use PowerMock to do it.
As usual, when dealing with PowerMock, you have to be really sure of what you are doing. You shouldn't need to use it with well-written code. Just follow the SOLID principles (see Chapter 2, Creating Mocks, for more information) and you shouldn't have the need to use this library.
PowerMock can be useful when dealing with legacy code or stubbing third-party libraries (you can check Chapter 8, Refactoring with Mockito, to see how to use PowerMock to refactor legacy code).
To use PowerMock, you have to add it to your classpath. Check ...