Skip to content

EranBoudjnah/RandomGenKt

Repository files navigation

RandomGenKt

Initialize instances of any class with generated data.

Version - RandomGenKt Version - DataSource Build Status License

Example

This is a Kotlin port of the Java library designed to generate random instances of any class.

This is great for demoing your app with interesting content, manually testing it with varying data, and even populating it with smart, random generated data in production.

Install

In your build.gradle, add the following:

dependencies {
    implementation("com.mitteloupe.randomgenkt:randomgenkt:2.0.1")
}

To include the default data generators, also include

dependencies {
    implementation("com.mitteloupe.randomgenkt:randomgenkt.datasource:2.0.1")
}

Usage

Kotlin

val randomGen = RandomGen.Builder<ObjectClass>()
	.ofKotlinClass<ObjectClass>()
	.withField("id")
	.returningSequentialInteger()
	.withField("uuid")
	.returningUuid()
	.build()

Java

RandomGen<ObjectClass> randomGen = new RandomGen.Builder<ObjectClass>()
	.ofJavaClass(ObjectClass.class)
	.withField("id")
	.returningSequentialInteger()
	.withField("uuid")
	.returningUuid()
	.build();

This will create a RandomGen instance producing ObjectClass instances with sequential IDs and random UUIDs.

To use the newly generated RandomGen, simply call:

Kotlin

val instance = randomGen()

Java

ObjectClass instance = randomGen.invoke();

What's New?

Version 2.0

This is an overhaul of RandomGenKt. It has been dusted, polished and refactored to align with modern conventions.

--

The Kotlin version adds the following:

  • Support for fields with lazy init
  • Lambdas
  • ofClass<Type>() instead of ofClass(Type::class.java)

Created by

Eran Boudjnah

License

MIT © Eran Boudjnah