diff --git a/src/main/java/com/devskiller/jfairy/producer/person/DefaultPersonProvider.java b/src/main/java/com/devskiller/jfairy/producer/person/DefaultPersonProvider.java index bb5ce1e4..47236066 100644 --- a/src/main/java/com/devskiller/jfairy/producer/person/DefaultPersonProvider.java +++ b/src/main/java/com/devskiller/jfairy/producer/person/DefaultPersonProvider.java @@ -212,8 +212,11 @@ public void generatePassword() { if (password != null) { return; } - // FIXME: Replace this with baseProducer - password = RandomStringUtils.randomAlphanumeric(8); + StringBuilder passwordPattern = new StringBuilder(); + for (int i = baseProducer.randomBetween(6, 14); i > 0; i--) { + passwordPattern.append(baseProducer.randomElement("?", "#")); + } + password = baseProducer.bothify(passwordPattern.toString()); } @Override diff --git a/src/test/groovy/com/devskiller/jfairy/FairySpec.groovy b/src/test/groovy/com/devskiller/jfairy/FairySpec.groovy index 3ff66a87..e30c5129 100644 --- a/src/test/groovy/com/devskiller/jfairy/FairySpec.groovy +++ b/src/test/groovy/com/devskiller/jfairy/FairySpec.groovy @@ -74,6 +74,28 @@ class FairySpec extends Specification { !firstPerson.fullName.equals(secondPerson.fullName) } + def "Second person should have the same password with the same random seed"() { + given: + Fairy firstFairy = Fairy.builder().withRandomSeed(10).build() + Fairy secondFairy = Fairy.builder().withRandomSeed(10).build() + + Person firstPerson = firstFairy.person() + Person secondPerson = secondFairy.person() + expect: + firstPerson.getPassword().equals(secondPerson.getPassword()) + } + + def "Second person should not have the same password with the different random seeds"() { + given: + Fairy firstFairy = Fairy.builder().withRandomSeed(10).build() + Fairy secondFairy = Fairy.builder().withRandomSeed(20).build() + + Person firstPerson = firstFairy.person() + Person secondPerson = secondFairy.person() + expect: + !firstPerson.getPassword().equals(secondPerson.getPassword()) + } + def "should use default DataMaster when custom not provided"() { given: Fairy fairy = Fairy.create();