Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of a Data Factory class with JavaFaker
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
You can’t perform that action at this time.