randomgenkt

Initialize instances of any class with generated data.

License

License

MIT
GroupId

GroupId

com.mitteloupe.randomgenkt
ArtifactId

ArtifactId

randomgenkt
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

randomgenkt
Initialize instances of any class with generated data.
Project URL

Project URL

https://github.com/EranBoudjnah/RandomGenKt.git
Source Code Management

Source Code Management

https://github.com/EranBoudjnah/RandomGenKt.git

Download randomgenkt

Dependencies

runtime (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.20
org.jetbrains.kotlin : kotlin-reflect jar 1.4.21
com.implimentz » unsafe jar 0.0.6

test (5)

Group / Artifact Type Version
junit : junit jar 4.13.2
org.hamcrest : hamcrest-core jar 2.2
org.mockito : mockito-core jar 3.9.0
org.mockito : mockito-inline jar 3.9.0
com.nhaarman.mockitokotlin2 : mockito-kotlin jar 2.2.0

Project Modules

There are no modules declared in this project.

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:1.0.1")
}

To include the default data generators, also include

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

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

Versions

Version
1.0.1