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 { public Person generateNewIdentity(Person person) { String newName = StaticIdentityCreator.createNewName(person); int newAge = StaticIdentityCreator.createNewAge(person); List<Person> newSiblings = StaticIdentityCreator...