Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure same passwords for same random seeds #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -7,7 +7,7 @@ import com.devskiller.jfairy.producer.person.Address

class DeAddressSpec extends Specification {

private final int SEED = 8
private final int SEED = 7
private Fairy fairy;
private Address address

Expand All @@ -18,42 +18,42 @@ class DeAddressSpec extends Specification {

def "should generate random street"() {
expect:
address.street == 'Sautterweg'
address.street == 'Unter dem Ahorn'
}

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

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

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

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

def "should return addressLine1 in de locale format"() {
expect:
address.addressLine1 == 'Sautterweg 21, 50'
address.addressLine1 == 'Unter dem Ahorn 19, 277'
}

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

def "should return address in de locale format"() {
expect:
address.toString() == "Sautterweg 21, 50${System.lineSeparator()}71138 Maxhütte Haidhof"
address.toString() == "Unter dem Ahorn 19, 277${System.lineSeparator()}45692 Hainsbach"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.devskiller.jfairy.producer.person.Address

class EnAddressSpec extends Specification {

private final int SEED = 7
private final int SEED = 8
private Fairy fairy;
private Address address

Expand All @@ -23,37 +23,37 @@ class EnAddressSpec extends Specification {

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

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

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

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 == "184 Washington Walk APT 32"
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.devskiller.jfairy.producer.person.Address

class EsAddressSpec extends Specification {

private final int SEED = 3
private final int SEED = 4
private Fairy fairy;
private Address address

Expand All @@ -18,42 +18,42 @@ class EsAddressSpec extends Specification {

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

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

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

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

def "should generate random city"() {
expect:
address.city == "Ciudad Real"
address.city == "Talavera de la Reina"
}

def "should return addressLine1 in es locale format"() {
expect:
address.addressLine1 == "Gran Vía, 32 64"
address.addressLine1 == "Cruz, 30 279"
}

def "should return addressLine2 in es locale format"() {
expect:
address.addressLine2 == "79.638 Ciudad Real"
address.addressLine2 == "65.216 Talavera de la Reina"
}

def "should return address in es locale format"() {
expect:
address.toString() == "Gran Vía, 32 64" + System.lineSeparator() + "79.638 Ciudad Real"
address.toString() == "Cruz, 30 279" + System.lineSeparator() + "65.216 Talavera de la Reina"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.devskiller.jfairy.producer.person.Address
import static java.lang.System.lineSeparator

class KaAddressSpec extends Specification {
private final int SEED = 8
private final int SEED = 7

private Fairy fairy
private Address address
Expand All @@ -21,41 +21,41 @@ 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 == "79"
}

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

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

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 == "7681, ზუგდიდი" // ZIP, city
}

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

def "should return address in GE locale format"() {
expect:
address.toString() == "6981, წყალტუბო${lineSeparator()}ნინოშვილის ქუჩა №179"
address.toString() == "7681, ზუგდიდი${lineSeparator()}ვაჟა–ფშაველას გამზირი №79, ბინა 87"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.devskiller.jfairy.producer.person.Address

class PlAddressSpec extends Specification {

private final int SEED = 8
private final int SEED = 10
private Fairy fairy;
private Address address

Expand All @@ -18,42 +18,42 @@ class PlAddressSpec extends Specification {

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

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

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

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

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

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

def "should return addressLine2 in pl locale format"() {
expect:
address.addressLine2 == "39-682 Zławieś Wielka"
address.addressLine2 == "80-469 Krasnobród"
}

def "should return address in pl locale format"() {
expect:
address.toString() == "Długorzeczna 62, 89" + System.lineSeparator() + "39-682 Zławieś Wielka"
address.toString() == "Zakamarek 115, 109" + System.lineSeparator() + "80-469 Krasnobród"
}

}
Loading