Test class with a new() call in it with Mockito
For the future I would recommend Eran Harel’s answer (refactoring moving new to factory that can be mocked). But if you don’t want to change the original source code, use very handy and unique feature: spies. From the documentation: You can create spies of real objects. When you use the spy then the real methods … Read more