diff --git a/src/main/java/org/hisp/dhis/utils/PredictableRandomizer.java b/src/main/java/org/hisp/dhis/utils/PredictableRandomizer.java index 8b1072b..600f978 100644 --- a/src/main/java/org/hisp/dhis/utils/PredictableRandomizer.java +++ b/src/main/java/org/hisp/dhis/utils/PredictableRandomizer.java @@ -47,8 +47,11 @@ public class PredictableRandomizer implements Randomizer { private final Faker faker; + private final long seed; + public PredictableRandomizer( long seed ) { + this.seed = seed; this.rnd = new Random( seed ); this.faker = new Faker( rnd ); } @@ -79,12 +82,6 @@ public List randomElementsFromList( List list, int size ) return resultList; } - @Override - public String randomString() - { - return this.faker.programmingLanguage().name(); - } - public String randomString( int size ) { return this.faker.lorem().characters( size, true, false ); @@ -132,11 +129,6 @@ public String randomNationalId() { return this.faker.idNumber().valid(); } - @Override - public Date randomAdultBirthday() { - return this.faker.date().birthday( 18, 80 ); - } - @Override public Date randomBirthday(int minAge, int maxAge){ return this.faker.date().birthday( minAge, maxAge ); @@ -191,4 +183,9 @@ private LocalDate toLocalDate( Date dateToConvert ) { return dateToConvert.toInstant().atZone( ZoneId.systemDefault() ).toLocalDate(); } + + @Override + public String toString() { + return "PredictableRandomizer("+ this.seed +")"; + } } diff --git a/src/main/java/org/hisp/dhis/utils/Randomizer.java b/src/main/java/org/hisp/dhis/utils/Randomizer.java index cdaf37c..d41d1cc 100644 --- a/src/main/java/org/hisp/dhis/utils/Randomizer.java +++ b/src/main/java/org/hisp/dhis/utils/Randomizer.java @@ -49,7 +49,9 @@ default T randomElementFromList( List list ) * * @return a String */ - String randomString(); + default String randomString(){ + return randomString(randomInt(20)); + } /** * Returns random string of alphabetical characters. @@ -125,7 +127,9 @@ default T randomElementFromList( List list ) * * @return a birthday date */ - Date randomAdultBirthday(); + default Date randomAdultBirthday(){ + return randomBirthday(18, 80); + }; /** * Generates random birthday date with age @@ -141,7 +145,7 @@ default T randomElementFromList( List list ) * @param wordCount number of words in the text * @return a long text */ - String randomLongText(int wordCount ); + String randomLongText( int wordCount ); /** * Generates random phone number