Kotlin port of RandomGen
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
gradle/wrapper
randomgenkt.datasource
randomgenkt
.gitignore
.travis.yml
LICENSE
README.md
TODO.txt
build.gradle.kts
gradle.properties
gradlew
gradlew.bat
settings.gradle.kts

README.md

RandomGenKt

Initialize instances of any class with generated data.

Build Status

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:1.0.0'
}

To include the default data generators, also include

implementation 'com.mitteloupe:randomgenkt.datasource:1.0.0'

Note: To add the BinTray repository in your maven repositories, also add the following:

repositories {
	maven {
		url "https://dl.bintray.com/shadowcra/RandomGenKt"
	}
}

Usage

Kotlin

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

Java

RandomGen<ObjectClass> randomGen = new RandomGen.Builder<ObjectClass>()
	.ofClass(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.generate()

Java

ObjectClass instance = randomGen.generate();

What's New?

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