public abstract class RandomBuilder extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
RandomBuilder.RandomRestriction
Interface to be implemented by all classes which can restrict the behaviour of the random builder and how it
assigns values to properties, which types, it creates, etc
|
| Constructor and Description |
|---|
RandomBuilder() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
aRandomArrayOf(Class<T> type)
Build an array of randomly populated instances of the supplied type.
|
static <T> T[] |
aRandomArrayOf(Class<T> type,
int min,
int max)
Build an array of randomly populated instances of the supplied type if a given size.
|
static <E extends Enum<E>> |
aRandomArrayOfEnum(Class<E> enumType)
Build an array of random values from the supplied enumeration.
|
static <E extends Enum<E>> |
aRandomArrayOfEnum(Class<E> enumType,
int min,
int max)
Build an array of random values from the supplied enumeration of a given size.
|
static Boolean |
aRandomBoolean()
Build a random
Boolean. |
static Byte |
aRandomByte()
Build a random
Byte. |
static byte[] |
aRandomByteArray()
Build a random array of bytes.
|
static Character |
aRandomChar()
Build a random
Character. |
static <T> Collection<T> |
aRandomCollectionOf(Class<T> type)
Build a collection of randomly populated instances of the supplied type.
|
static <T> Collection<T> |
aRandomCollectionOf(Class<T> type,
int min,
int max)
Build a collection of randomly populated instances of the supplied type if a given size.
|
static Date |
aRandomDate()
Build a random
Date with an year either side of today. |
static BigDecimal |
aRandomDecimal()
Build a random
BigDecimal. |
static Double |
aRandomDouble()
Build a random
Double. |
static <E extends Enum<E>> |
aRandomEnum(Class<E> enumType)
Build a random instance of the supplied enumeration.
|
static Float |
aRandomFloat()
Build a random
Float. |
static <T> T |
aRandomInstanceOf(Class<T> type)
Build a random instance of the supplied type.
|
static <T> T |
aRandomInstanceOf(Class<T> type,
List<RandomBuilder.RandomRestriction> restrictions)
Build a random instance of the supplied type.
|
static <T> T |
aRandomInstanceOf(Class<T> type,
RandomBuilder.RandomRestriction... restrictions)
Build a random instance of the supplied type.
|
static Instant |
aRandomInstant()
Build a random
ZonedDateTime with an year either side of today. |
static Integer |
aRandomInteger()
Build a random
Integer. |
static Integer |
aRandomInteger(int min,
int max)
Build a random
Integer within the supplied minumum and maximum range. |
static <T> List<T> |
aRandomListOf(Class<T> type)
Build a list of randomly populated instances of the supplied type.
|
static <T> List<T> |
aRandomListOf(Class<T> type,
int min,
int max)
Build a random list of randomly populated instances of the supplied type if a given size.
|
static LocalDate |
aRandomLocalDate()
Build a random
LocalDate with an year either side of today. |
static LocalDateTime |
aRandomLocalDateTime()
Build a random
LocalDateTime with an year either side of today. |
static LocalTime |
aRandomLocalTime()
Build a random
LocalTime within 12 hours either side of now. |
static Long |
aRandomLong()
Build a random
Long. |
static Long |
aRandomLong(int min,
int max)
Build a random
Long within the supplied minumum and maximum range. |
static Short |
aRandomShort()
Build a random
Short. |
static Short |
aRandomShort(short min,
short max)
Build a random
Short within the supplied minumum and maximum range. |
static String |
aRandomString()
Build a random
String containing alphanumeric characters. |
static String |
aRandomString(int length)
Build a random
String containing alphanumeric characters of the specfied size. |
static ZonedDateTime |
aRandomZonedDateTime()
Build a random
ZonedDateTime with an year either side of today. |
static <P> RandomBuilder.RandomRestriction |
collectionSize(int size)
Build and instance of a
RandomBuilder.RandomRestriction which will limit the size of all collections to the specified
size |
static <P> RandomBuilder.RandomRestriction |
collectionSize(int min,
int max)
Build and instance of a
RandomBuilder.RandomRestriction which will limit the size of all collections to within the
specified range |
static <P> RandomBuilder.RandomRestriction |
collectionSizeForPath(String path,
int size)
Build and instance of a
RandomBuilder.RandomRestriction which will set the size of the collection at the specified path |
static <P> RandomBuilder.RandomRestriction |
collectionSizeForPath(String path,
int min,
int max)
Build and instance of a
RandomBuilder.RandomRestriction which will limit the size of the collection at the specifed
path |
static <P> RandomBuilder.RandomRestriction |
collectionSizeForProperty(String property,
int size)
Build and instance of a
RandomBuilder.RandomRestriction which will set the size of the collection at the specified
property |
static <P> RandomBuilder.RandomRestriction |
collectionSizeForProperty(String property,
int min,
int max)
Build and instance of a
RandomBuilder.RandomRestriction which will limit the size of the collection at the specifed
property |
static RandomBuilder.RandomRestriction |
excludePath(String path)
Build and instance of a
RandomBuilder.RandomRestriction which will prevent the value at the path being assigned any
value |
static RandomBuilder.RandomRestriction |
excludeProperty(String property)
Build and instance of a
RandomBuilder.RandomRestriction which will prevent the property being assigned any value |
static <T> RandomBuilder.RandomRestriction |
factory(Class<T> type,
ValueFactory<T> factory)
Build and instance of a
RandomBuilder.RandomRestriction which uses the ValueFactory to create instances of the
specified type. |
static <T> T |
oneOf(T... rangeOfValues)
Return one of the specified range of values.
|
static RandomBuilder.RandomRestriction |
path(String path,
Object value)
Build and instance of a
RandomBuilder.RandomRestriction which assigns the value to the specific path |
static RandomBuilder.RandomRestriction |
path(String path,
ValueFactory<?> factory)
Build and instance of a
RandomBuilder.RandomRestriction which assigns an ValueFactory derived value to the
specific path |
static RandomBuilder.RandomRestriction |
property(String property,
Object value)
Build and instance of a
RandomBuilder.RandomRestriction which assigns the value to the specific property. |
static RandomBuilder.RandomRestriction |
property(String property,
ValueFactory<?> factory)
Build and instance of a
RandomBuilder.RandomRestriction which assigns an ValueFactory derived value to the
specific property. |
static <P> RandomBuilder.RandomRestriction |
subtype(Class<P> superType,
Class<? extends P>... subTypes)
Build and instance of a
RandomBuilder.RandomRestriction which will use any of the given sub types of a super type when
instantiating the super type. |
static <P> RandomBuilder.RandomRestriction |
subtype(Class<P> superType,
Class<? extends P> subType)
Build and instance of a
RandomBuilder.RandomRestriction which will use the given subtype of a super type when
instantiating the subtype. |
public static String aRandomString()
String containing alphanumeric characters. For example
String aRandomName = RandomBuilder.aRandomString();
String.public static String aRandomString(int length)
String containing alphanumeric characters of the specfied size. For example
String aRandomName = RandomBuilder.aRandomString(10);
String.public static Integer aRandomInteger()
Integer. For example
Integer aRandomAge = RandomBuilder.aRandomInteger();
Integer.public static Integer aRandomInteger(int min, int max)
Integer within the supplied minumum and maximum range. For example
Integer aRandomAge = RandomBuilder.aRandomInteger(1,100);
min - the minimum value can bemax - the maximum value can beInteger within the supplied minumum and maximum range.public static Short aRandomShort()
Short. For example
Short aRandomAge = RandomBuilder.aRandomShort();
.Short.public static Short aRandomShort(short min, short max)
Short within the supplied minumum and maximum range. For example
Short aRandomAge = RandomBuilder.aRandomShort(1,100);
min - the minimum value can bemax - the maximum value can beShort within the supplied minumum and maximum range.public static Long aRandomLong()
Long. For example
Long aRandomAge = RandomBuilder.aRandomLong(1,100);
Long.public static Long aRandomLong(int min, int max)
Long within the supplied minumum and maximum range. For example
Long aRandomAge = RandomBuilder.aRandomLong(1,100L);
min - the minimum value can bemax - the maximum value can beLong within the supplied minumum and maximum range.public static Double aRandomDouble()
Double. For example
Double aRandomHeight = RandomBuilder.aRandomDouble();
Double.public static Float aRandomFloat()
Float. For example
Float aRandomHeight = RandomBuilder.aRandomFloat();
Float.public static <T> T oneOf(T... rangeOfValues)
String aRandomName = RandomBuilder.oneOf("Bob", "Alice", "Jane");
T - the type of the valuerangeOfValues - the range of values to pick a value frompublic static Boolean aRandomBoolean()
Boolean. For example
Boolean aRandomHasSibilings = RandomBuilder.aRandomBoolean();
Boolean.public static Date aRandomDate()
Date with an year either side of today. For example
Date aRandomBirthday = RandomBuilder.aRandomDate();
Date with an year either side of today.public static LocalDate aRandomLocalDate()
LocalDate with an year either side of today. For example
LocalDate aRandomBirthday = RandomBuilder.aRandomLocalDate();
LocalDate with an year either side of today.public static LocalDateTime aRandomLocalDateTime()
LocalDateTime with an year either side of today. For example
LocalDateTime aRandomBirthday = RandomBuilder.aRandomLocalDateTime();
LocalDateTime with an year either side of today.public static LocalTime aRandomLocalTime()
LocalTime within 12 hours either side of now. For example
LocalTime aRandomTime = RandomBuilder.aRandomLocalTime();
aRandomLocalTime within 12 hours either side of now.public static ZonedDateTime aRandomZonedDateTime()
ZonedDateTime with an year either side of today. For example
ZonedDateTime aRandomBirthday = RandomBuilder.aRandomZonedDateTime();
ZonedDateTime with an year either side of today.public static Instant aRandomInstant()
ZonedDateTime with an year either side of today. For example
ZonedDateTime aRandomBirthday = RandomBuilder.aRandomZonedDateTime();
ZonedDateTime with an year either side of today.public static BigDecimal aRandomDecimal()
BigDecimal. For example
BigDecimal aRandomWeight = RandomBuilder.aRandomDecimal();
BigDecimal.public static Byte aRandomByte()
Byte. For example
BigDecimal aRandomByte = RandomBuilder.aRandomByte();
Byte.public static byte[] aRandomByteArray()
byte [] aRandomID = RandomBuilder.aRandomByteArray();
public static Character aRandomChar()
Character. For example
Character aRandomInitial = RandomBuilder.aRandomCharacter();
Character.public static <E extends Enum<E>> E aRandomEnum(Class<E> enumType)
Gender aRandomGender = RandomBuilder.aRandomEnum(Gender.class);
enumType - the enumeration to create a random instance ofpublic static <E extends Enum<E>> E[] aRandomArrayOfEnum(Class<E> enumType)
EyeColour [] eyeColours = RandomBuilder.aRandomArrayOfEnum(EyeColour.class);
enumType - the enumeration to create an array ofpublic static <E extends Enum<E>> E[] aRandomArrayOfEnum(Class<E> enumType, int min, int max)
EyeColour [] eyeColours = RandomBuilder.aRandomArrayOfEnum(EyeColour.class, 2, 5);
enumType - the enumeration to create an array ofmin - the minimum size the array can bemax - the maxiumum size the array can bepublic static <T> T[] aRandomArrayOf(Class<T> type)
Person [] aRandomCrowd = RandomBuilder.aRandomArrayOf(Person.class);
type - the type to create an array ofpublic static <T> T[] aRandomArrayOf(Class<T> type, int min, int max)
Person [] aRandomCrowd = RandomBuilder.aRandomArrayOf(Person.class,10,50);
type - the type to create an array ofmin - the minimum size the array can bemax - the maxiumum size the array can bepublic static <T> Collection<T> aRandomCollectionOf(Class<T> type)
Collection aRandomCrowd = RandomBuilder.aRandomCollectionOf(Person.class);
type - the type to create a collection ofpublic static <T> Collection<T> aRandomCollectionOf(Class<T> type, int min, int max)
Collection aRandomCrowd = RandomBuilder.aRandomCollectionOf(Person.class,10,50);
type - the type to create a collection ofmin - the minimum size the collection can bemax - the maxiumum size the collection can bepublic static <T> List<T> aRandomListOf(Class<T> type)
List aRandomCrowd = RandomBuilder.aRandomListOf(Person.class);
type - the type to create a list ofpublic static <T> List<T> aRandomListOf(Class<T> type, int min, int max)
List aRandomCrowd = RandomBuilder.aRandomListOf(Person.class);
type - the type to create a random list ofmin - the minimum size the list can bemax - the maxiumum size the list can bepublic static <T> T aRandomInstanceOf(Class<T> type)
Person aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class);
type - the type to create a random instance ofrestrictions - an array of restrictions which control how the random instance is builtpublic static <T> T aRandomInstanceOf(Class<T> type, RandomBuilder.RandomRestriction... restrictions)
Person aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class);
For examples on how to use restrictions to define the random object See:
path(String, Object)property(String, Object)excludePath(String)excludeProperty(String)subtype(Class, Class)subtype(Class, Class...)collectionSize(int)collectionSize(int, int)collectionSizeForPath(String, int)collectionSizeForProperty(String, int)collectionSizeForProperty(String, int, int)
type - the type to create a random instance ofrestrictions - an array of restrictions which control how the random instance is builtpublic static <T> T aRandomInstanceOf(Class<T> type, List<RandomBuilder.RandomRestriction> restrictions)
List restrictions = new ArrayList();
restrictions.add(RandomBuilder.path("person.surname","Smith"));
restrictions.add(RandomBuilder.property("age",25));
Person aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class, restrictions);
For examples on how to use restrictions to define the random object See:
path(String, Object)property(String, Object)excludePath(String)excludeProperty(String)subtype(Class, Class)subtype(Class, Class...)collectionSize(int)collectionSize(int, int)collectionSizeForPath(String, int)collectionSizeForProperty(String, int)collectionSizeForProperty(String, int, int)
type - the type to create a random instance ofrestrictions - an array of restrictions which control how the random instance is builtpublic static RandomBuilder.RandomRestriction property(String property, Object value)
RandomBuilder.RandomRestriction which assigns the value to the specific property. For example
Person aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class, RandomBuilder.property("surname", "Smith"));
property - the property to assign e.g. "name"value - the value to assign the property e.g. "Jane Doe"public static RandomBuilder.RandomRestriction property(String property, ValueFactory<?> factory)
RandomBuilder.RandomRestriction which assigns an ValueFactory derived value to the
specific property. For example
Person aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class, RandomBuilder.property("surname", ValueFactories.oneOf("Smith","Brown"));
property - the property to assignvalue - the value to assign the propertypublic static <T> RandomBuilder.RandomRestriction factory(Class<T> type, ValueFactory<T> factory)
RandomBuilder.RandomRestriction which uses the ValueFactory to create instances of the
specified type. For example
Shape aRandomPerson = RandomBuilder.aRandomInstanceOf(Person.class, RandomBuilder.factory(Email.class, new EmailFactory());
type - the type to use the instance factory forfactory - the instance factory to usepublic static RandomBuilder.RandomRestriction excludeProperty(String property)
RandomBuilder.RandomRestriction which will prevent the property being assigned any valueproperty - the path to assign e.g. "name"public static RandomBuilder.RandomRestriction path(String path, Object value)
RandomBuilder.RandomRestriction which assigns the value to the specific pathpath - the path to assign e.g. "person.name"value - the value to assign the path e.g. "Jane Doe"public static RandomBuilder.RandomRestriction path(String path, ValueFactory<?> factory)
RandomBuilder.RandomRestriction which assigns an ValueFactory derived value to the
specific pathpath - the path to assign e.g. "person.name"value - the value to assign the pathpublic static RandomBuilder.RandomRestriction excludePath(String path)
RandomBuilder.RandomRestriction which will prevent the value at the path being assigned any
valuepath - the path to assign e.g. "person.name"public static <P> RandomBuilder.RandomRestriction subtype(Class<P> superType, Class<? extends P> subType)
RandomBuilder.RandomRestriction which will use the given subtype of a super type when
instantiating the subtype.superType - the super typesubType - the sub type to use when creating an instance of the super typepublic static <P> RandomBuilder.RandomRestriction subtype(Class<P> superType, Class<? extends P>... subTypes)
RandomBuilder.RandomRestriction which will use any of the given sub types of a super type when
instantiating the super type.superType - the super typesubType - the sub types to use when creating an instance of the super typepublic static <P> RandomBuilder.RandomRestriction collectionSize(int size)
RandomBuilder.RandomRestriction which will limit the size of all collections to the specified
sizesize - the size of the collectionpublic static <P> RandomBuilder.RandomRestriction collectionSize(int min, int max)
RandomBuilder.RandomRestriction which will limit the size of all collections to within the
specified rangemin - the minimum size the collections can bemax - the maximum size the collections can bepublic static <P> RandomBuilder.RandomRestriction collectionSizeForPath(String path, int size)
RandomBuilder.RandomRestriction which will set the size of the collection at the specified pathpath - the path to assign the collection size of e.g. "person.siblings"size - the size of the collectionpublic static <P> RandomBuilder.RandomRestriction collectionSizeForPath(String path, int min, int max)
RandomBuilder.RandomRestriction which will limit the size of the collection at the specifed
pathmin - the minimum size the collections can bemax - the maximum size the collections can bepublic static <P> RandomBuilder.RandomRestriction collectionSizeForProperty(String property, int size)
RandomBuilder.RandomRestriction which will set the size of the collection at the specified
propertyproperty - the property to assign the collection size of e.g. "person.siblings"size - the size of the collectionpublic static <P> RandomBuilder.RandomRestriction collectionSizeForProperty(String property, int min, int max)
RandomBuilder.RandomRestriction which will limit the size of the collection at the specifed
propertymin - the minimum size the collections can bemax - the maximum size the collections can beCopyright © 2018. All rights reserved.