RandomGen
Initialize instances of any class with generated data.
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
License
MIT © Eran Boudjnah
