Initialize instances of any class with generated data.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
gradle/wrapper
randomgen.datasource
randomgen
.gitignore
.travis.yml
LICENSE
README.md
TODO.txt
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

RandomGen

Initialize instances of any class with generated data.

Build Status

Example

Inspired by Cesar Ferreira's RxPeople, I thought I'd implement an abstraction of the idea, so you could 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:randomgen:1.4.0'
}

To include the default data generators, also include

implementation 'com.mitteloupe:randomgen.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/RandomGen"
	}
}

Usage

Java

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

Kotlin

val randomGen = RandomGen.Builder<ObjectClass>()
	.ofClass(ObjectClass::class.java)
	.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:

Java

ObjectClass instance = randomGen.generate();

Kotlin

val instance = randomGen.generate()

Created by

Eran Boudjnah

License

MIT © Eran Boudjnah