Last active
June 14, 2021 17:59
-
-
Save lovewithmind/f4a878f83e0f7fcf277b1d8f41b56b85 to your computer and use it in GitHub Desktop.
Person data builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersonTest { | |
@Test | |
public void shouldReturnFalseForInCorrectEmail() { | |
Person person = PersonBuilder.defaultBuilder() | |
.email("99999") | |
.build(); | |
boolean isValidEmail = person.isValidEmail(); | |
assertFalse(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) { | |
this.name = name; | |
return this; | |
} | |
public PersonBuilder email(final String email) { | |
this.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( | |
identificationNumber, | |
name, | |
email, | |
phoneNumber, | |
mobileNumber, | |
homeAddress, | |
officeAddress | |
); | |
} | |
public static PersonBuilder defaultBuilder(){ | |
return PersonBuilder | |
.builder() | |
.name("John") | |
.email("john@gmail.com") | |
.phoneNumber("888888") | |
.mobileNumber("888888"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment