public class EasyRandomParameters
extends java.lang.Object
EasyRandom
instance.Modifier and Type | Class and Description |
---|---|
static class |
EasyRandomParameters.Range<T>
Utility class to hold a range of values.
|
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
DEFAULT_CHARSET
Default charset for Strings.
|
static EasyRandomParameters.Range<java.lang.Integer> |
DEFAULT_COLLECTION_SIZE_RANGE
Default collection size range.
|
static int |
DEFAULT_DATE_RANGE
Default date range in which dates will be generated: [now - 10 years, now + 10 years].
|
static EasyRandomParameters.Range<java.time.ZonedDateTime> |
DEFAULT_DATES_RANGE
Default dates range.
|
static int |
DEFAULT_OBJECT_POOL_SIZE
Number of different objects to generate for a type.
|
static int |
DEFAULT_RANDOMIZATION_DEPTH
Default value for randomization depth, which mean, that randomization depth is unlimited
|
static long |
DEFAULT_SEED
Default seed.
|
static EasyRandomParameters.Range<java.lang.Integer> |
DEFAULT_STRING_LENGTH_RANGE
Default string length size.
|
Constructor and Description |
---|
EasyRandomParameters() |
Modifier and Type | Method and Description |
---|---|
EasyRandomParameters |
charset(java.nio.charset.Charset charset)
Set the charset to use for character based fields.
|
EasyRandomParameters |
collectionSizeRange(int minCollectionSize,
int maxCollectionSize)
Set the collection size range.
|
EasyRandomParameters |
dateRange(java.time.LocalDate min,
java.time.LocalDate max)
Set the date range.
|
EasyRandomParameters |
excludeField(java.util.function.Predicate<java.lang.reflect.Field> predicate)
Exclude a field from being randomized.
|
EasyRandomParameters |
excludeType(java.util.function.Predicate<java.lang.Class<?>> predicate)
Exclude a type from being randomized.
|
EasyRandomParameters |
exclusionPolicy(ExclusionPolicy exclusionPolicy)
Provide a custom exclusion policy.
|
java.nio.charset.Charset |
getCharset() |
EasyRandomParameters.Range<java.lang.Integer> |
getCollectionSizeRange() |
EasyRandomParameters.Range<java.time.LocalDate> |
getDateRange() |
ExclusionPolicy |
getExclusionPolicy() |
java.util.Set<java.util.function.Predicate<java.lang.reflect.Field>> |
getFieldExclusionPredicates() |
ObjectFactory |
getObjectFactory() |
int |
getObjectPoolSize() |
int |
getRandomizationDepth() |
RandomizerProvider |
getRandomizerProvider() |
long |
getSeed() |
EasyRandomParameters.Range<java.lang.Integer> |
getStringLengthRange() |
EasyRandomParameters.Range<java.time.LocalTime> |
getTimeRange() |
java.util.Set<java.util.function.Predicate<java.lang.Class<?>>> |
getTypeExclusionPredicates() |
EasyRandomParameters |
ignoreRandomizationErrors(boolean ignoreRandomizationErrors)
With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null.
|
boolean |
isIgnoreRandomizationErrors() |
boolean |
isOverrideDefaultInitialization() |
boolean |
isScanClasspathForConcreteTypes() |
EasyRandomParameters |
objectFactory(ObjectFactory objectFactory)
Provide a custom object factory.
|
EasyRandomParameters |
objectPoolSize(int objectPoolSize)
Set the number of different objects to generate for a type.
|
EasyRandomParameters |
overrideDefaultInitialization(boolean overrideDefaultInitialization)
Should default initialization of field values be overridden?
E.g.
|
EasyRandomParameters |
randomizationDepth(int randomizationDepth)
Set the randomization depth for objects graph.
|
<T> EasyRandomParameters |
randomize(java.lang.Class<T> type,
Randomizer<T> randomizer)
Register a custom randomizer for a given type.
|
<T> EasyRandomParameters |
randomize(java.util.function.Predicate<java.lang.reflect.Field> predicate,
Randomizer<T> randomizer)
Register a custom randomizer for the given field predicate.
|
EasyRandomParameters |
randomizerProvider(RandomizerProvider randomizerProvider)
Provide a custom randomizer provider.
|
EasyRandomParameters |
randomizerRegistry(RandomizerRegistry registry)
Register a
RandomizerRegistry . |
EasyRandomParameters |
scanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
Should the classpath be scanned for concrete types when a field with an interface or abstract
class type is encountered?
Deactivated by default.
|
EasyRandomParameters |
seed(long seed)
Set the initial random seed.
|
void |
setCharset(java.nio.charset.Charset charset) |
void |
setCollectionSizeRange(EasyRandomParameters.Range<java.lang.Integer> collectionSizeRange) |
void |
setDateRange(EasyRandomParameters.Range<java.time.LocalDate> dateRange) |
void |
setExclusionPolicy(ExclusionPolicy exclusionPolicy) |
void |
setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors) |
void |
setObjectFactory(ObjectFactory objectFactory) |
void |
setObjectPoolSize(int objectPoolSize) |
void |
setOverrideDefaultInitialization(boolean overrideDefaultInitialization) |
void |
setRandomizationDepth(int randomizationDepth) |
void |
setRandomizerProvider(RandomizerProvider randomizerProvider) |
void |
setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes) |
void |
setSeed(long seed) |
void |
setStringLengthRange(EasyRandomParameters.Range<java.lang.Integer> stringLengthRange) |
void |
setTimeRange(EasyRandomParameters.Range<java.time.LocalTime> timeRange) |
EasyRandomParameters |
stringLengthRange(int minStringLength,
int maxStringLength)
Set the string length range.
|
EasyRandomParameters |
timeRange(java.time.LocalTime min,
java.time.LocalTime max)
Set the time range.
|
public static final long DEFAULT_SEED
public static final java.nio.charset.Charset DEFAULT_CHARSET
public static final EasyRandomParameters.Range<java.lang.Integer> DEFAULT_COLLECTION_SIZE_RANGE
public static final int DEFAULT_OBJECT_POOL_SIZE
public static final int DEFAULT_RANDOMIZATION_DEPTH
public static final EasyRandomParameters.Range<java.lang.Integer> DEFAULT_STRING_LENGTH_RANGE
public static final int DEFAULT_DATE_RANGE
public static final EasyRandomParameters.Range<java.time.ZonedDateTime> DEFAULT_DATES_RANGE
public EasyRandomParameters.Range<java.lang.Integer> getCollectionSizeRange()
public void setCollectionSizeRange(EasyRandomParameters.Range<java.lang.Integer> collectionSizeRange)
public EasyRandomParameters.Range<java.time.LocalDate> getDateRange()
public void setDateRange(EasyRandomParameters.Range<java.time.LocalDate> dateRange)
public EasyRandomParameters.Range<java.time.LocalTime> getTimeRange()
public void setTimeRange(EasyRandomParameters.Range<java.time.LocalTime> timeRange)
public EasyRandomParameters.Range<java.lang.Integer> getStringLengthRange()
public void setStringLengthRange(EasyRandomParameters.Range<java.lang.Integer> stringLengthRange)
public long getSeed()
public void setSeed(long seed)
public int getObjectPoolSize()
public void setObjectPoolSize(int objectPoolSize)
public int getRandomizationDepth()
public void setRandomizationDepth(int randomizationDepth)
public java.nio.charset.Charset getCharset()
public void setCharset(java.nio.charset.Charset charset)
public boolean isScanClasspathForConcreteTypes()
public void setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
public boolean isOverrideDefaultInitialization()
public void setOverrideDefaultInitialization(boolean overrideDefaultInitialization)
public boolean isIgnoreRandomizationErrors()
public void setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors)
public ExclusionPolicy getExclusionPolicy()
public void setExclusionPolicy(ExclusionPolicy exclusionPolicy)
public ObjectFactory getObjectFactory()
public void setObjectFactory(ObjectFactory objectFactory)
public RandomizerProvider getRandomizerProvider()
public void setRandomizerProvider(RandomizerProvider randomizerProvider)
public java.util.Set<java.util.function.Predicate<java.lang.reflect.Field>> getFieldExclusionPredicates()
public java.util.Set<java.util.function.Predicate<java.lang.Class<?>>> getTypeExclusionPredicates()
public <T> EasyRandomParameters randomize(java.util.function.Predicate<java.lang.reflect.Field> predicate, Randomizer<T> randomizer)
T
- The field typepredicate
- to identify the fieldrandomizer
- to registerEasyRandomParameters
instance for method chainingFieldPredicates
public <T> EasyRandomParameters randomize(java.lang.Class<T> type, Randomizer<T> randomizer)
T
- The field typetype
- class of the type to randomizerandomizer
- the custom Randomizer
to useEasyRandomParameters
instance for method chainingpublic EasyRandomParameters excludeField(java.util.function.Predicate<java.lang.reflect.Field> predicate)
predicate
- to identify the field to excludeEasyRandomParameters
instance for method chainingFieldPredicates
public EasyRandomParameters excludeType(java.util.function.Predicate<java.lang.Class<?>> predicate)
predicate
- to identify the type to excludeEasyRandomParameters
instance for method chainingFieldPredicates
public EasyRandomParameters exclusionPolicy(ExclusionPolicy exclusionPolicy)
exclusionPolicy
- to useEasyRandomParameters
instance for method chainingpublic EasyRandomParameters objectFactory(ObjectFactory objectFactory)
objectFactory
- to useEasyRandomParameters
instance for method chainingpublic EasyRandomParameters randomizerProvider(RandomizerProvider randomizerProvider)
randomizerProvider
- to useEasyRandomParameters
instance for method chainingpublic EasyRandomParameters seed(long seed)
seed
- the initial seedEasyRandomParameters
instance for method chainingpublic EasyRandomParameters collectionSizeRange(int minCollectionSize, int maxCollectionSize)
minCollectionSize
- the minimum collection sizemaxCollectionSize
- the maximum collection sizeEasyRandomParameters
instance for method chainingpublic EasyRandomParameters stringLengthRange(int minStringLength, int maxStringLength)
minStringLength
- the minimum string lengthmaxStringLength
- the maximum string lengthEasyRandomParameters
instance for method chainingpublic EasyRandomParameters objectPoolSize(int objectPoolSize)
objectPoolSize
- the number of objects to generate in the poolEasyRandomParameters
instance for method chainingpublic EasyRandomParameters randomizationDepth(int randomizationDepth)
randomizationDepth
- the maximum randomization depthEasyRandomParameters
instance for method chainingpublic EasyRandomParameters charset(java.nio.charset.Charset charset)
charset
- the charset to useEasyRandomParameters
instance for method chainingpublic EasyRandomParameters dateRange(java.time.LocalDate min, java.time.LocalDate max)
min
- datemax
- dateEasyRandomParameters
instance for method chainingpublic EasyRandomParameters timeRange(java.time.LocalTime min, java.time.LocalTime max)
min
- timemax
- timeEasyRandomParameters
instance for method chainingpublic EasyRandomParameters randomizerRegistry(RandomizerRegistry registry)
RandomizerRegistry
.registry
- the RandomizerRegistry
to registerEasyRandomParameters
instance for method chainingpublic EasyRandomParameters scanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
scanClasspathForConcreteTypes
- whether to scan the classpath or notEasyRandomParameters
instance for method chainingpublic EasyRandomParameters ignoreRandomizationErrors(boolean ignoreRandomizationErrors)
ignoreRandomizationErrors
- whether to silently ignore randomization errors or notEasyRandomParameters
instance for method chainingpublic EasyRandomParameters overrideDefaultInitialization(boolean overrideDefaultInitialization)
strings
and integers
fields below be kept untouched
or should they be randomized.
public class Bean {
Set<String> strings = new HashSet<>();
List<Integer> integers;
public Bean() {
integers = Arrays.asList(1, 2, 3);
}
}
Deactivated by default.overrideDefaultInitialization
- whether to override default initialization of field values or notEasyRandomParameters
instance for method chainingCopyright © 2019. All Rights Reserved.