Skip to content

Instantly share code, notes, and snippets.

Last active June 14, 2021 17:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Person data builder
class PersonTest {
public void shouldReturnFalseForInCorrectEmail() {
Person person = PersonBuilder.defaultBuilder()
boolean isValidEmail = person.isValidEmail();
class PersonBuilder {
private Integer identificationNumber;
private String name;
private String email;
private String phoneNumber;
private String mobileNumber;
private Address homeAddress;
private Address officeAddress;
public static PersonBuilder builder() {
return new PersonBuilder();
public PersonBuilder identificationNumber(
final Integer identificationNumber
) {
this.identificationNumber = identificationNumber;
return this;
public PersonBuilder name(final String name) { = name;
return this;
public PersonBuilder email(final String email) { = email;
return this;
public PersonBuilder phoneNumber(final String phoneNumber) {
this.phoneNumber = phoneNumber;
return this;
public PersonBuilder mobileNumber(
final String mobileNumber
) {
this.mobileNumber = mobileNumber;
return this;
public PersonBuilder homeAddress(
final Address homeAddress
) {
this.homeAddress = homeAddress;
return this;
public PersonBuilder officeAddress(
final Address officeAddress
) {
this.officeAddress = officeAddress;
return this;
public Person build() {
return new Person(
public static PersonBuilder defaultBuilder(){
return PersonBuilder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment