O'Reilly logo

Mockito Cookbook by Marcin Grzejszczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring the classes that use static methods

In this recipe, we will refactor classes that call static methods to execute business logic instead of having their external dependencies properly defined.

Getting ready

Similar to the previous examples, our system under test is a system that generates a new identity for a given person. Each person can have a name, an age, and siblings. Please remember that the following class is very poorly designed (all the test examples are written for JUnit; please refer to Chapter 1, Getting Started with Mockito, for the TestNG configuration and Chapter 7, Verifying Behavior with Object Matchers, for the AssertJ configuration and the BDDAssertions static imports):

public class BadlyDesignedNewPersonGenerator { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required