Package org.jeasy.random
Class EasyRandomParameters
java.lang.Object
org.jeasy.random.EasyRandomParameters
Parameters of an
EasyRandom instance.- Author:
- Mahmoud Ben Hassine ([email protected])
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUtility class to hold a range of values. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetDefault charset for Strings.static final EasyRandomParameters.Range<Integer>Default collection size range.static final intDefault date range in which dates will be generated: [now - 10 years, now + 10 years].static final EasyRandomParameters.Range<ZonedDateTime>Default dates range.static final intNumber of different objects to generate for a type.static final intDefault value for randomization depth, which mean, that randomization depth is unlimitedstatic final longDefault seed.static final EasyRandomParameters.Range<Integer>Default string length size. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbypassSetters(boolean bypassSetters) Flag to bypass setters if any and use reflection directly instead.Set the charset to use for character based fields.collectionSizeRange(int minCollectionSize, int maxCollectionSize) Set the collection size range.copy()Return a shallow copy of randomization parameters.Set the date range.excludeField(BiPredicate<Field, Object> predicate) excludeField(Predicate<Field> predicate) Exclude a field from being randomized.excludeType(Predicate<Class<?>> predicate) Exclude a type from being randomized.exclusionPolicy(ExclusionPolicy exclusionPolicy) Provide a custom exclusion policy.intintlonggetSeed()ignoreRandomizationErrors(boolean ignoreRandomizationErrors) With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null.booleanbooleanbooleanbooleanobjectFactory(ObjectFactory objectFactory) Provide a custom object factory.objectPoolSize(int objectPoolSize) Set the number of different objects to generate for a type.overrideDefaultInitialization(boolean overrideDefaultInitialization) Should default initialization of field values be overridden? E.g.randomizationDepth(int randomizationDepth) Set the randomization depth for objects graph.randomize(Class<T> type, Randomizer<T> randomizer) Register a custom randomizer for a given type.randomize(BiPredicate<Field, Object> predicate, Randomizer<T> randomizer) Register a custom randomizer for the given field predicate.randomize(Predicate<Field> predicate, Randomizer<T> randomizer) randomizerProvider(RandomizerProvider randomizerProvider) Provide a custom randomizer provider.randomizerRegistry(RandomizerRegistry registry) Register aRandomizerRegistry.scanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes) Should the classpath be scanned for concrete types when a field with an interface or abstract class type is encountered?seed(long seed) Set the initial random seed.voidsetBypassSetters(boolean bypassSetters) voidsetCharset(Charset charset) voidsetCollectionSizeRange(EasyRandomParameters.Range<Integer> collectionSizeRange) setCustomRandomizerRegistry(CustomRandomizerRegistry customRandomizerRegistry) voidsetDateRange(EasyRandomParameters.Range<LocalDate> dateRange) setExclusionPolicy(ExclusionPolicy exclusionPolicy) voidsetIgnoreRandomizationErrors(boolean ignoreRandomizationErrors) voidsetObjectFactory(ObjectFactory objectFactory) voidsetObjectPoolSize(int objectPoolSize) voidsetOverrideDefaultInitialization(boolean overrideDefaultInitialization) voidsetRandomizationDepth(int randomizationDepth) voidsetRandomizerProvider(RandomizerProvider randomizerProvider) voidsetScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes) voidsetSeed(long seed) voidsetStringLengthRange(EasyRandomParameters.Range<Integer> stringLengthRange) voidsetTimeRange(EasyRandomParameters.Range<LocalTime> timeRange) stringLengthRange(int minStringLength, int maxStringLength) Set the string length range.Set the time range.
-
Field Details
-
DEFAULT_SEED
public static final long DEFAULT_SEEDDefault seed.- See Also:
-
DEFAULT_CHARSET
Default charset for Strings. -
DEFAULT_COLLECTION_SIZE_RANGE
Default collection size range. -
DEFAULT_OBJECT_POOL_SIZE
public static final int DEFAULT_OBJECT_POOL_SIZENumber of different objects to generate for a type.- See Also:
-
DEFAULT_RANDOMIZATION_DEPTH
public static final int DEFAULT_RANDOMIZATION_DEPTHDefault value for randomization depth, which mean, that randomization depth is unlimited- See Also:
-
DEFAULT_STRING_LENGTH_RANGE
Default string length size. -
DEFAULT_DATE_RANGE
public static final int DEFAULT_DATE_RANGEDefault date range in which dates will be generated: [now - 10 years, now + 10 years].- See Also:
-
DEFAULT_DATES_RANGE
Default dates range.
-
-
Constructor Details
-
EasyRandomParameters
public EasyRandomParameters()Create a newEasyRandomParameterswith default values.
-
-
Method Details
-
getCollectionSizeRange
-
setCollectionSizeRange
-
getDateRange
-
setDateRange
-
getTimeRange
-
setTimeRange
-
getStringLengthRange
-
setStringLengthRange
-
getSeed
public long getSeed() -
setSeed
public void setSeed(long seed) -
getObjectPoolSize
public int getObjectPoolSize() -
setObjectPoolSize
public void setObjectPoolSize(int objectPoolSize) -
getRandomizationDepth
public int getRandomizationDepth() -
setRandomizationDepth
public void setRandomizationDepth(int randomizationDepth) -
getCharset
-
setCharset
-
isScanClasspathForConcreteTypes
public boolean isScanClasspathForConcreteTypes() -
setScanClasspathForConcreteTypes
public void setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes) -
isOverrideDefaultInitialization
public boolean isOverrideDefaultInitialization() -
setOverrideDefaultInitialization
public void setOverrideDefaultInitialization(boolean overrideDefaultInitialization) -
isIgnoreRandomizationErrors
public boolean isIgnoreRandomizationErrors() -
setIgnoreRandomizationErrors
public void setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors) -
isBypassSetters
public boolean isBypassSetters() -
setBypassSetters
public void setBypassSetters(boolean bypassSetters) -
getExclusionPolicy
-
setExclusionPolicy
-
getObjectFactory
-
setObjectFactory
-
getRandomizerProvider
-
setRandomizerProvider
-
getFieldExclusionPredicates
-
getTypeExclusionPredicates
-
setCustomRandomizerRegistry
public EasyRandomParameters setCustomRandomizerRegistry(CustomRandomizerRegistry customRandomizerRegistry) -
getCustomRandomizerRegistry
-
randomize
public <T> EasyRandomParameters randomize(BiPredicate<Field, Object> predicate, Randomizer<T> randomizer) Register a custom randomizer for the given field predicate. The predicate must at least specify the field type- Type Parameters:
T- The field type- Parameters:
predicate- to identify the fieldrandomizer- to register- Returns:
- the current
EasyRandomParametersinstance for method chaining - See Also:
-
randomize
-
randomize
Register a custom randomizer for a given type.- Type Parameters:
T- The field type- Parameters:
type- class of the type to randomizerandomizer- the customRandomizerto use- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
excludeField
Exclude a field from being randomized.- Parameters:
predicate- to identify the field to exclude- Returns:
- the current
EasyRandomParametersinstance for method chaining - See Also:
-
excludeField
-
excludeType
Exclude a type from being randomized.- Parameters:
predicate- to identify the type to exclude- Returns:
- the current
EasyRandomParametersinstance for method chaining - See Also:
-
exclusionPolicy
Provide a custom exclusion policy.- Parameters:
exclusionPolicy- to use- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
objectFactory
Provide a custom object factory.- Parameters:
objectFactory- to use- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
randomizerProvider
Provide a custom randomizer provider.- Parameters:
randomizerProvider- to use- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
seed
Set the initial random seed.- Parameters:
seed- the initial seed- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
collectionSizeRange
Set the collection size range.- Parameters:
minCollectionSize- the minimum collection sizemaxCollectionSize- the maximum collection size- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
stringLengthRange
Set the string length range.- Parameters:
minStringLength- the minimum string lengthmaxStringLength- the maximum string length- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
objectPoolSize
Set the number of different objects to generate for a type.- Parameters:
objectPoolSize- the number of objects to generate in the pool- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
randomizationDepth
Set the randomization depth for objects graph.- Parameters:
randomizationDepth- the maximum randomization depth- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
charset
Set the charset to use for character based fields.- Parameters:
charset- the charset to use- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
dateRange
Set the date range.- Parameters:
min- datemax- date- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
timeRange
Set the time range.- Parameters:
min- timemax- time- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
randomizerRegistry
Register aRandomizerRegistry.- Parameters:
registry- theRandomizerRegistryto register- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
scanClasspathForConcreteTypes
Should the classpath be scanned for concrete types when a field with an interface or abstract class type is encountered?Deactivated by default.
- Parameters:
scanClasspathForConcreteTypes- whether to scan the classpath or not- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
ignoreRandomizationErrors
With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null.Deactivated by default.
- Parameters:
ignoreRandomizationErrors- whether to silently ignore randomization errors or not- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
overrideDefaultInitialization
Should default initialization of field values be overridden? E.g. should the values of thestringsandintegersfields below be kept untouched or should they be randomized.
Deactivated by default.public class Bean { Set<String> strings = new HashSet<>(); List<Integer> integers; public Bean() { integers = Arrays.asList(1, 2, 3); } }- Parameters:
overrideDefaultInitialization- whether to override default initialization of field values or not- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
bypassSetters
Flag to bypass setters if any and use reflection directly instead. False by default.- Parameters:
bypassSetters- true if setters should be ignored- Returns:
- the current
EasyRandomParametersinstance for method chaining
-
copy
Return a shallow copy of randomization parameters.- Returns:
- a shallow copy of randomization parameters.
-