class RandomClassProvider: Any

Provider functionality for generating random class instances.

Inspired by Creating a random instance of any class in Kotlin blog post.

Methods

configure

fun configure(configurator: RandomProviderConfig.()->Unit)

Applies configurator to this RandomClassProvider.

Parameters

Name Description
configurator: RandomProviderConfig.()->Unit

ReturnValue

Name Description
Unit

new

fun new(): RandomClassProvider

Creates a new instance of this RandomClassProvider.

IF FakerConfig.randomProviderConfig was configured THEN new instance will be created with a copy of that configuration, ELSE a new instance is created with a new instance of default configuration as defined in RandomProviderConfig.

ReturnValue

Name Description
RandomClassProvider

copy

fun copy(): RandomClassProvider

Creates a copy of this RandomClassProvider instance with a copy of its config.

ReturnValue

Name Description
RandomClassProvider

reset

fun reset()

Resets config to defaults for this RandomClassProvider instance.

ReturnValue

Name Description
Unit

randomClassInstance

fun <T : Any> randomClassInstance(): T

Creates an instance of T. If T has a parameterless public constructor then it will be used to create an instance of this class, otherwise a constructor with minimal number of parameters will be used with randomly-generated values.

ReturnValue

Name Description
T

randomClassInstance

inline fun <T : Any> randomClassInstance(configurator: RandomProviderConfig.()->Unit): T

Creates an instance of T. If T has a parameterless public constructor then it will be used to create an instance of this class, otherwise a constructor with minimal number of parameters will be used with randomly-generated values.

Parameters

Name Description
configurator: RandomProviderConfig.()->Unit

configure instance creation.

ReturnValue

Name Description
T