Creating custom AssertJ assertions
In this recipe, we will create a custom AssertJ assertion. Please refer to the previous recipe for the presented assertions in the test because in the current recipe, we will combine them into our custom assertions:
Getting ready
For this recipe, our system under test will be a NewPersonGenerator
class that will call an external service, NewIdentityCreator
, to generate a new identity for the current person, as shown in the following code:
public class NewPersonGenerator { private final NewIdentityCreator newIdentityCreator; public NewPersonGenerator(NewIdentityCreator newIdentityCreator) { this.newIdentityCreator = newIdentityCreator; } public Person generateNewIdentity(Person person) { String newName = newIdentityCreator.createNewName(person); ...
Get Mockito Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.