Last active
November 15, 2020 16:55
-
-
Save eliasnogueira/24eabcddd29d95641cf7181d1a3a227d to your computer and use it in GitHub Desktop.
Example of a Data Factory class with JavaFaker
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
public class LoanDataFactory { | |
private static Faker faker; | |
private static final int MIN_VALID_INSTALLMENTS = 2; | |
private static final int MAX_VALID_INSTALLMENTS = 18; | |
private static final int MAX_NUMBER_OF_DECIMALS = 2; | |
private static final Long MIN_VALID_AMOUNT = Long.valueOf("1000"); | |
private static final Long MAX_VALID_AMOUNT = Long.valueOf("40000"); | |
private LoanDataFactory() { | |
faker = new Faker(); | |
} | |
public static Loan createLoan() { | |
return new LoanBuilder(). | |
name(faker.name().firstName()). | |
email(faker.internet().emailAddress()) | |
.amount(BigDecimal.valueOf( | |
faker.number().randomDouble( | |
MAX_NUMBER_OF_DECIMALS, MIN_VALID_AMOUNT, MAX_VALID_AMOUNT))) | |
.installments(faker.number().numberBetween(MIN_VALID_INSTALLMENTS, MAX_VALID_INSTALLMENTS)).build(); | |
} | |
// other methods ignored | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment