Skip to content

Commit

Permalink
Support for multiple maximum and minimum set age operations
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpietrzak committed Feb 25, 2016
1 parent aeab240 commit 1e92c9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import io.codearte.jfairy.producer.BaseProducer;
import io.codearte.jfairy.producer.company.Company;

import java.util.Optional;

/**
* @author jkubrynski@gmail.com
* @since 2013-11-16
*/
public final class PersonProperties {

private static Optional<Integer> minimumAge = Optional.empty();
private static Optional<Integer> maximumAge = Optional.empty();

private PersonProperties() {
}

Expand Down Expand Up @@ -41,16 +46,20 @@ public static PersonProperty ageBetween(final int minAge, final int maxAge) {
@Override
public void apply(PersonProvider person, BaseProducer baseProducer) {
person.setAge(baseProducer.randomBetween(minAge, maxAge));
minimumAge = Optional.of(minAge);
maximumAge = Optional.of(maxAge);
}
};
}

public static PersonProperty minAge(final int minAge) {
return ageBetween(minAge, PersonProvider.MAX_AGE);
minimumAge = Optional.of(minAge);
return ageBetween(minAge, maximumAge.orElse(PersonProvider.MAX_AGE));
}

public static PersonProperty maxAge(final int maxAge) {
return ageBetween(PersonProvider.MIN_AGE, maxAge);
maximumAge = Optional.of(maxAge);
return ageBetween(minimumAge.orElse(PersonProvider.MIN_AGE), maxAge);
}

public static PersonProperty telephoneFormat(final String telephoneFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class PersonSpec extends Specification {
person.age() > 98
}

def "should create person older than 10 years and younger than 10 years"() {
when:
Person person = fairy.person(minAge(10), maxAge(10))
then:
person.age() == 10
}

def "birth date and age should be related"() {
when:
def person = fairy.person(ageBetween(32, 32))
Expand Down

0 comments on commit 1e92c9b

Please sign in to comment.