Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
random utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sokomishalov committed Sep 17, 2019
1 parent 527dcbb commit 5fadc6c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions commons-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<guava.version>28.1-jre</guava.version>
<reactor.version>3.2.12.RELEASE</reactor.version>
<slf4j.version>1.7.28</slf4j.version>
<easy-random.version>4.0.0</easy-random.version>
</properties>


Expand Down Expand Up @@ -95,6 +96,12 @@
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-random-core</artifactId>
<version>${easy-random.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@file:Suppress("unused", "RemoveExplicitTypeArguments")

package ru.sokomishalov.commons.core.random

import org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric
import org.jeasy.random.EasyRandom
import org.jeasy.random.EasyRandomParameters
import java.nio.charset.StandardCharsets.UTF_8

/**
* @author sokomishalov
*/
val EASY_RANDOM_PARAMS: EasyRandomParameters = EasyRandomParameters()
.seed((0L..1000L).random())
.objectPoolSize(100)
.randomizationDepth(3)
.charset(UTF_8)
.stringLengthRange(5, 20)
.collectionSizeRange(0, 10)
.scanClasspathForConcreteTypes(true)
.overrideDefaultInitialization(false)
.ignoreRandomizationErrors(true)


inline fun <reified T> randomPojo(): T {
return EasyRandom(EASY_RANDOM_PARAMS).nextObject(T::class.java)
}

inline fun <reified T> randomPojoSequence() = sequence<T> {
while (true) {
yield(randomPojo<T>())
}
}

fun randomString(length: Int = 20): String = randomAlphanumeric(length)

0 comments on commit 5fadc6c

Please sign in to comment.