Praise for PowerMock
I’m generally a fan of unit-testing. I’m even quite happy to refactor existing code to make it test-friendly. However sometimes this is just not possible, either because it is third-party code, or because it has special performance or security constraints.
- Creating mock objects for final classes;
- Configuring mock responses for static methods;
- Mocking responses to invocations of the new operator!
It all worked for me just as advertised - added the dependency to the maven pom, added two annotations (@RunWith and @PrepareForTest) to the test case class, and then used normal Mockito functionality plus a couple of PowerMockito.mock/PowerMockito.mockStatic/PowerMockito.mockNew calls to extend the existing test coverage to areas it previously could not reach.