diff --git a/commons-core/pom.xml b/commons-core/pom.xml index 6b2ed38..d8695f9 100644 --- a/commons-core/pom.xml +++ b/commons-core/pom.xml @@ -23,6 +23,7 @@ 28.1-jre 3.2.12.RELEASE 1.7.28 + 4.0.0 @@ -95,6 +96,12 @@ ${guava.version} + + org.jeasy + easy-random-core + ${easy-random.version} + + org.slf4j slf4j-api diff --git a/commons-core/src/main/kotlin/ru/sokomishalov/commons/core/random/RandomUtils.kt b/commons-core/src/main/kotlin/ru/sokomishalov/commons/core/random/RandomUtils.kt new file mode 100644 index 0000000..5a8ded0 --- /dev/null +++ b/commons-core/src/main/kotlin/ru/sokomishalov/commons/core/random/RandomUtils.kt @@ -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 randomPojo(): T { + return EasyRandom(EASY_RANDOM_PARAMS).nextObject(T::class.java) +} + +inline fun randomPojoSequence() = sequence { + while (true) { + yield(randomPojo()) + } +} + +fun randomString(length: Int = 20): String = randomAlphanumeric(length) \ No newline at end of file