Class KRandomParameters
-
- All Implemented Interfaces:
public class KRandomParameters
Parameters of an KRandom instance.
Mahmoud Ben Hassine ([email protected])
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
KRandomParameters.Range
Utility class to hold a range of values.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description KRandomParameters()
Create a new KRandomParameters with default values.
-
Method Summary
Modifier and Type Method Description long
getSeed()
void
setSeed(long seed)
int
getObjectPoolSize()
void
setObjectPoolSize(int objectPoolSize)
int
getRandomizationDepth()
void
setRandomizationDepth(int randomizationDepth)
Charset
getCharset()
void
setCharset(Charset charset)
KRandomParameters.Range<Integer>
getCollectionSizeRange()
void
setCollectionSizeRange(KRandomParameters.Range<Integer> collectionSizeRange)
KRandomParameters.Range<Integer>
getStringLengthRange()
void
setStringLengthRange(KRandomParameters.Range<Integer> stringLengthRange)
KRandomParameters.Range<LocalDate>
getDateRange()
void
setDateRange(KRandomParameters.Range<LocalDate> dateRange)
KRandomParameters.Range<LocalTime>
getTimeRange()
void
setTimeRange(KRandomParameters.Range<LocalTime> timeRange)
ExclusionPolicy
getExclusionPolicy()
void
setExclusionPolicy(ExclusionPolicy exclusionPolicy)
ObjectFactory
getObjectFactory()
void
setObjectFactory(ObjectFactory objectFactory)
RandomizerProvider
getRandomizerProvider()
void
setRandomizerProvider(RandomizerProvider randomizerProvider)
Set<Predicate<Field>>
getFieldExclusionPredicates()
Set<Predicate<Class<out Object>>>
getTypeExclusionPredicates()
boolean
isScanClasspathForConcreteTypes()
boolean
isOverrideDefaultInitialization()
boolean
isIgnoreRandomizationErrors()
boolean
isBypassSetters()
<T> KRandomParameters
randomize(Predicate<Field> predicate, Randomizer<T> randomizer)
Register a custom randomizer for the given field predicate. <T> KRandomParameters
randomize(Class<T> type, Randomizer<T> randomizer)
Register a custom randomizer for a given type. KRandomParameters
excludeField(Predicate<Field> predicate)
Exclude a field from being randomized. KRandomParameters
excludeType(Predicate<Class<out Object>> predicate)
Exclude a type from being randomized. KRandomParameters
exclusionPolicy(ExclusionPolicy exclusionPolicy)
Provide a custom exclusion policy. KRandomParameters
objectFactory(ObjectFactory objectFactory)
Provide a custom object factory. KRandomParameters
randomizerProvider(RandomizerProvider randomizerProvider)
Provide a custom randomizer provider. KRandomParameters
seed(long seed)
Set the initial random seed. KRandomParameters
collectionSizeRange(int minCollectionSize, int maxCollectionSize)
Set the collection size range. KRandomParameters
stringLengthRange(int minStringLength, int maxStringLength)
Set the string length range. KRandomParameters
objectPoolSize(int objectPoolSize)
Set the number of different objects to generate for a type. KRandomParameters
randomizationDepth(int randomizationDepth)
Set the randomization depth for objects graph. KRandomParameters
charset(Charset charset)
Set the charset to use for character based fields. KRandomParameters
dateRange(LocalDate min, LocalDate max)
Set the date range. KRandomParameters
timeRange(LocalTime min, LocalTime max)
Set the time range. KRandomParameters
randomizerRegistry(RandomizerRegistry registry)
Register a RandomizerRegistry. KRandomParameters
scanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
Should the classpath be scanned for concrete types when a field with an interface or abstract class type is encountered? KRandomParameters
ignoreRandomizationErrors(boolean ignoreRandomizationErrors)
With this parameter, any randomization error will be silently ignored and the corresponding field will be set to null. KRandomParameters
overrideDefaultInitialization(boolean overrideDefaultInitialization)
Should default initialization of field values be overridden? KRandomParameters
bypassSetters(boolean bypassSetters)
Flag to bypass setters if any and use reflection directly instead. KRandomParameters
copy()
Return a shallow copy of randomization parameters. void
setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
void
setOverrideDefaultInitialization(boolean overrideDefaultInitialization)
void
setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors)
void
setBypassSetters(boolean bypassSetters)
-
-
Constructor Detail
-
KRandomParameters
KRandomParameters()
Create a new KRandomParameters with default values.
-
-
Method Detail
-
getSeed
long getSeed()
-
setSeed
void setSeed(long seed)
-
getObjectPoolSize
int getObjectPoolSize()
-
setObjectPoolSize
void setObjectPoolSize(int objectPoolSize)
-
getRandomizationDepth
int getRandomizationDepth()
-
setRandomizationDepth
void setRandomizationDepth(int randomizationDepth)
-
getCharset
Charset getCharset()
-
setCharset
void setCharset(Charset charset)
-
getCollectionSizeRange
KRandomParameters.Range<Integer> getCollectionSizeRange()
-
setCollectionSizeRange
void setCollectionSizeRange(KRandomParameters.Range<Integer> collectionSizeRange)
-
getStringLengthRange
KRandomParameters.Range<Integer> getStringLengthRange()
-
setStringLengthRange
void setStringLengthRange(KRandomParameters.Range<Integer> stringLengthRange)
-
getDateRange
KRandomParameters.Range<LocalDate> getDateRange()
-
setDateRange
void setDateRange(KRandomParameters.Range<LocalDate> dateRange)
-
getTimeRange
KRandomParameters.Range<LocalTime> getTimeRange()
-
setTimeRange
void setTimeRange(KRandomParameters.Range<LocalTime> timeRange)
-
getExclusionPolicy
ExclusionPolicy getExclusionPolicy()
-
setExclusionPolicy
void setExclusionPolicy(ExclusionPolicy exclusionPolicy)
-
getObjectFactory
ObjectFactory getObjectFactory()
-
setObjectFactory
void setObjectFactory(ObjectFactory objectFactory)
-
getRandomizerProvider
RandomizerProvider getRandomizerProvider()
-
setRandomizerProvider
void setRandomizerProvider(RandomizerProvider randomizerProvider)
-
getFieldExclusionPredicates
Set<Predicate<Field>> getFieldExclusionPredicates()
-
getTypeExclusionPredicates
Set<Predicate<Class<out Object>>> getTypeExclusionPredicates()
-
isScanClasspathForConcreteTypes
boolean isScanClasspathForConcreteTypes()
-
isOverrideDefaultInitialization
boolean isOverrideDefaultInitialization()
-
isIgnoreRandomizationErrors
boolean isIgnoreRandomizationErrors()
-
isBypassSetters
boolean isBypassSetters()
-
randomize
<T> KRandomParameters randomize(Predicate<Field> predicate, Randomizer<T> randomizer)
Register a custom randomizer for the given field predicate. The predicate must at least specify the field type
- Parameters:
predicate
- to identify the fieldrandomizer
- to register- Returns:
the current KRandomParameters instance for method chaining
-
randomize
<T> KRandomParameters randomize(Class<T> type, Randomizer<T> randomizer)
Register a custom randomizer for a given type.
- Parameters:
type
- class of the type to randomizerandomizer
- the custom Randomizer to use- Returns:
the current KRandomParameters instance for method chaining
-
excludeField
KRandomParameters excludeField(Predicate<Field> predicate)
Exclude a field from being randomized.
- Parameters:
predicate
- to identify the field to exclude- Returns:
the current KRandomParameters instance for method chaining
-
excludeType
KRandomParameters excludeType(Predicate<Class<out Object>> predicate)
Exclude a type from being randomized.
- Parameters:
predicate
- to identify the type to exclude- Returns:
the current KRandomParameters instance for method chaining
-
exclusionPolicy
KRandomParameters exclusionPolicy(ExclusionPolicy exclusionPolicy)
Provide a custom exclusion policy.
- Parameters:
exclusionPolicy
- to use- Returns:
the current KRandomParameters instance for method chaining
-
objectFactory
KRandomParameters objectFactory(ObjectFactory objectFactory)
Provide a custom object factory.
- Parameters:
objectFactory
- to use- Returns:
the current KRandomParameters instance for method chaining
-
randomizerProvider
KRandomParameters randomizerProvider(RandomizerProvider randomizerProvider)
Provide a custom randomizer provider.
- Parameters:
randomizerProvider
- to use- Returns:
the current KRandomParameters instance for method chaining
-
seed
KRandomParameters seed(long seed)
Set the initial random seed.
- Parameters:
seed
- the initial seed- Returns:
the current KRandomParameters instance for method chaining
-
collectionSizeRange
KRandomParameters collectionSizeRange(int minCollectionSize, int maxCollectionSize)
Set the collection size range.
- Parameters:
minCollectionSize
- the minimum collection sizemaxCollectionSize
- the maximum collection size- Returns:
the current KRandomParameters instance for method chaining
-
stringLengthRange
KRandomParameters stringLengthRange(int minStringLength, int maxStringLength)
Set the string length range.
- Parameters:
minStringLength
- the minimum string lengthmaxStringLength
- the maximum string length- Returns:
the current KRandomParameters instance for method chaining
-
objectPoolSize
KRandomParameters objectPoolSize(int 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 KRandomParameters instance for method chaining
-
randomizationDepth
KRandomParameters randomizationDepth(int randomizationDepth)
Set the randomization depth for objects graph.
- Parameters:
randomizationDepth
- the maximum randomization depth- Returns:
the current KRandomParameters instance for method chaining
-
charset
KRandomParameters charset(Charset charset)
Set the charset to use for character based fields.
- Parameters:
charset
- the charset to use- Returns:
the current KRandomParameters instance for method chaining
-
dateRange
KRandomParameters dateRange(LocalDate min, LocalDate max)
Set the date range.
- Parameters:
min
- datemax
- date- Returns:
the current KRandomParameters instance for method chaining
-
timeRange
KRandomParameters timeRange(LocalTime min, LocalTime max)
Set the time range.
- Parameters:
min
- timemax
- time- Returns:
the current KRandomParameters instance for method chaining
-
randomizerRegistry
KRandomParameters randomizerRegistry(RandomizerRegistry registry)
Register a RandomizerRegistry.
- Parameters:
registry
- the RandomizerRegistry to register- Returns:
the current KRandomParameters instance for method chaining
-
scanClasspathForConcreteTypes
KRandomParameters 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.
- Parameters:
scanClasspathForConcreteTypes
- whether to scan the classpath or not- Returns:
the current KRandomParameters instance for method chaining
-
ignoreRandomizationErrors
KRandomParameters ignoreRandomizationErrors(boolean 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 KRandomParameters instance for method chaining
-
overrideDefaultInitialization
KRandomParameters overrideDefaultInitialization(boolean overrideDefaultInitialization)
Should default initialization of field values be overridden? E.g. should the values of the
strings
andintegers
fields 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 KRandomParameters instance for method chaining
-
bypassSetters
KRandomParameters bypassSetters(boolean 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 KRandomParameters instance for method chaining
-
copy
KRandomParameters copy()
Return a shallow copy of randomization parameters.
- Returns:
a shallow copy of randomization parameters.
-
setScanClasspathForConcreteTypes
void setScanClasspathForConcreteTypes(boolean scanClasspathForConcreteTypes)
-
setOverrideDefaultInitialization
void setOverrideDefaultInitialization(boolean overrideDefaultInitialization)
-
setIgnoreRandomizationErrors
void setIgnoreRandomizationErrors(boolean ignoreRandomizationErrors)
-
setBypassSetters
void setBypassSetters(boolean bypassSetters)
-
-
-
-