Skip to content

Commit

Permalink
Ensure same passwords for same random seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
rweisleder committed May 28, 2020
1 parent ed0f567 commit 9817525
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/com/devskiller/jfairy/FairyDeSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FairyDeSpec extends Specification {
when:
Person person = fairy.person();
then:
person.address.city == 'Schlitz'
person.address.city == 'Eschenburg'
}

}
2 changes: 1 addition & 1 deletion src/test/groovy/com/devskiller/jfairy/FairyFrSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FairyFrSpec extends Specification {
when:
Person person = fairy.person();
then:
person.address.city == 'Échirolles'
person.address.city == 'Rosny-sous-Bois'
}

}
6 changes: 3 additions & 3 deletions src/test/groovy/com/devskiller/jfairy/FairyKaSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ class FairyKaSpec extends Specification {
when:
Person person = fairy.person()
then:
person.address.street == 'აგლაძის ქუჩა' // Agladze Street
person.address.street == 'კოსტავას' // Kostava Street
}

def "Should create Georgian city"() {
when:
Person person = fairy.person()
then:
person.address.city == 'ზესტაფონი' // Sagarejo
person.address.city == 'გორი' // Gori
}

def "Should create Georgian ID card"() {
when:
Person person = fairy.person()
then:
person.nationalIdentityCardNumber == 'Nლ4757825'
person.nationalIdentityCardNumber == 'Nხ4686471'
}
}
22 changes: 22 additions & 0 deletions src/test/groovy/com/devskiller/jfairy/FairySpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/com/devskiller/jfairy/FairyZhSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class FairyZhSpec extends Specification {
when:
Person person = fairy.person()
then:
person.address.addressLine1 == '杭州市内环路45号'
person.address.addressLine1 == '广州市滨江路153号'
}

def "Should create Chinese city"() {
when:
Person person = fairy.person()
then:
person.address.city == '杭州'
person.address.city == '广州'
}

/********************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ class DeAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == 'Sautterweg'
address.street == 'Sonnenburger Weg'
}

def "should generate random streetNumber"() {
expect:
address.streetNumber == '21'
address.streetNumber == '99'
}

def "should generate random apartmentNumber"() {
expect:
address.apartmentNumber == '50'
address.apartmentNumber == ''
}

def "should generate random postalCode"() {
expect:
address.postalCode == '71138'
address.postalCode == '98126'
}

def "should generate random city"() {
expect:
address.city == 'Maxhütte Haidhof'
address.city == 'Wetschen'
}

def "should return addressLine1 in de locale format"() {
expect:
address.addressLine1 == 'Sautterweg 21, 50'
address.addressLine1 == 'Sonnenburger Weg 99'
}

def "should return addressLine2 in de locale format"() {
expect:
address.addressLine2 == '71138 Maxhütte Haidhof'
address.addressLine2 == '98126 Wetschen'
}

def "should return address in de locale format"() {
expect:
address.toString() == "Sautterweg 21, 50${System.lineSeparator()}71138 Maxhütte Haidhof"
address.toString() == "Sonnenburger Weg 99${System.lineSeparator()}98126 Wetschen"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ class EnAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == "Washington Walk"
address.street == "Herzi Street"
}

def "should generate random streetNumber"() {
expect:
address.streetNumber == "42"
address.streetNumber == "63"
}

def "should generate random apartmentNumber"() {
expect:
address.apartmentNumber == "86"
address.apartmentNumber == ""
}

def "should generate random postalCode"() {
expect:
address.postalCode == "86645"
address.postalCode == "42856"
}

def "should generate random city"() {
expect:
address.city == "San Francisco"
address.city == "Miami"
}

def "should return addressLine1 in en locale format"() {
expect:
address.addressLine1 == "42 Washington Walk APT 86"
address.addressLine1 == "63 Herzi Street"
}

def "should return addressLine2 in en locale format"() {
expect:
address.addressLine2 == "San Francisco 86645"
address.addressLine2 == "Miami 42856"
}

def "should return address in en locale format"() {
expect:
address.toString() == "42 Washington Walk APT 86" + System.lineSeparator() + "San Francisco 86645"
address.toString() == "63 Herzi Street" + System.lineSeparator() + "Miami 42856"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ class EsAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == "Gran Vía"
address.street == "Colón"
}

def "should generate random streetNumber"() {
expect:
address.streetNumber == "32"
address.streetNumber == "101"
}

def "should generate random apartmentNumber"() {
expect:
address.apartmentNumber == "64"
address.apartmentNumber == ""
}

def "should generate random postalCode"() {
expect:
address.postalCode == "79.638"
address.postalCode == "79.240"
}

def "should generate random city"() {
expect:
address.city == "Ciudad Real"
address.city == "Algeciras"
}

def "should return addressLine1 in es locale format"() {
expect:
address.addressLine1 == "Gran Vía, 32 64"
address.addressLine1 == "Colón, 101"
}

def "should return addressLine2 in es locale format"() {
expect:
address.addressLine2 == "79.638 Ciudad Real"
address.addressLine2 == "79.240 Algeciras"
}

def "should return address in es locale format"() {
expect:
address.toString() == "Gran Vía, 32 64" + System.lineSeparator() + "79.638 Ciudad Real"
address.toString() == "Colón, 101" + System.lineSeparator() + "79.240 Algeciras"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class KaAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == "ნინოშვილის ქუჩა"
address.street == "დავით აღმაშენებლის გამზირი"
}

def "should generate random streetNumber"() {
expect:
address.streetNumber == "179"
address.streetNumber == "110"
}

def "should generate random apartmentNumber"() {
Expand All @@ -36,26 +36,26 @@ class KaAddressSpec extends Specification {

def "should generate random postalCode"() {
expect:
address.postalCode == "6981"
address.postalCode == "6003"
}

def "should generate random city"() {
expect:
address.city == "წყალტუბო"
address.city == "გარდაბანი"
}

def "should return addressLine1 in GE locale format"() {
expect:
address.addressLine1 == "6981, წყალტუბო" // ZIP, city
address.addressLine1 == "6003, გარდაბანი" // ZIP, city
}

def "should return addressLine2 in GE locale format"() {
expect:
address.addressLine2 == "ნინოშვილის ქუჩა №179" // street & number & appartment
address.addressLine2 == "დავით აღმაშენებლის გამზირი №110" // street & number & appartment
}

def "should return address in GE locale format"() {
expect:
address.toString() == "6981, წყალტუბო${lineSeparator()}ნინოშვილის ქუჩა №179"
address.toString() == "6003, გარდაბანი${lineSeparator()}დავით აღმაშენებლის გამზირი №110"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ class PlAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == "Długorzeczna"
address.street == "Prosta"
}

def "should generate random streetNumber"() {
expect:
address.streetNumber == "62"
address.streetNumber == "71"
}

def "should generate random apartmentNumber"() {
expect:
address.apartmentNumber == "89"
address.apartmentNumber == ""
}

def "should generate random postalCode"() {
expect:
address.postalCode == "39-682"
address.postalCode == "26-077"
}

def "should generate random city"() {
expect:
address.city == "Zławieś Wielka"
address.city == "Pniewy"
}

def "should return addressLine1 in pl locale format"() {
expect:
address.addressLine1 == "Długorzeczna 62, 89"
address.addressLine1 == "Prosta 71"
}

def "should return addressLine2 in pl locale format"() {
expect:
address.addressLine2 == "39-682 Zławieś Wielka"
address.addressLine2 == "26-077 Pniewy"
}

def "should return address in pl locale format"() {
expect:
address.toString() == "Długorzeczna 62, 89" + System.lineSeparator() + "39-682 Zławieś Wielka"
address.toString() == "Prosta 71" + System.lineSeparator() + "26-077 Pniewy"
}

}
Loading

0 comments on commit 9817525

Please sign in to comment.