Working with PowerMock
Sometimes, we cannot unit test our code, as the special Java constructs hide the testing impediments (a LAN connection or database connection in a private method, final method, static method, or initialization block), such as private methods, final methods and classes, static methods and initialization blocks, new operator, and so on. We refactor code for testability (explained in the Designing for testability with Mockito section) and, sometimes, compromise a good design for the sole purpose of testability. For example, final classes and methods are avoided, private methods are converted to protected or default, or unnecessarily moved to a collaborator class, static methods are avoided completely, and so on. This is done simply because of the limitations of the existing frameworks. Also, these aren't just feature limitations; they are intentional choices. Mockito could do the things PowerMock does, but it doesn't because those are test smells and strong indications...