Skip to content

Commit

Permalink
Add kotest module
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Oct 14, 2023
1 parent 1c3e7e9 commit 2a60cbc
Show file tree
Hide file tree
Showing 13 changed files with 1,956 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@ public FixtureMonkeyOptionsBuilder javaConstraintGenerator(JavaConstraintGenerat
return this;
}

public FixtureMonkeyOptionsBuilder javaTypeArbitraryGeneratorSet(
Function<JavaConstraintGenerator, JavaTypeArbitraryGeneratorSet> generateJavaTypeArbitrarySet
) {
this.generateJavaTypeArbitrarySet = generateJavaTypeArbitrarySet;
return this;
}

public FixtureMonkeyOptionsBuilder javaTimeArbitraryGeneratorSet(
Function<JavaConstraintGenerator, JavaTimeArbitraryGeneratorSet> generateJavaTimeArbitrarySet
) {
this.generateJavaTimeArbitrarySet = generateJavaTimeArbitrarySet;
return this;
}

public FixtureMonkeyOptions build() {
ObjectPropertyGenerator defaultObjectPropertyGenerator = defaultIfNull(
this.defaultObjectPropertyGenerator,
Expand Down
49 changes: 49 additions & 0 deletions fixture-monkey-kotest/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}

plugins {
id "org.jetbrains.kotlin.jvm" version "${KOTLIN_VERSION}"
id "org.jlleitschuh.gradle.ktlint" version "10.2.0"
}

repositories {
mavenCentral()
}

ext {
KOTEST_VERSION = "5.6.2"
}

dependencies {
api(project(":fixture-monkey-kotlin"))
api("io.kotest:kotest-property-jvm:${KOTEST_VERSION}")

implementation("org.jetbrains.kotlin:kotlin-stdlib:${KOTLIN_VERSION}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${KOTLIN_VERSION}")


testImplementation("org.junit.jupiter:junit-jupiter-engine:${JUNIT_JUPITER_VERSION}")
testImplementation("org.junit.platform:junit-platform-engine:${JUNIT_ENGINE_VERSION}")
testImplementation("org.assertj:assertj-core:3.22.0")
testImplementation("io.kotest:kotest-runner-junit5:${KOTEST_VERSION}")
testImplementation("io.kotest:kotest-assertions-core:${KOTEST_VERSION}")
}

jar {
manifest {
attributes(
"Specification-Title": artifactName,
"Specification-Version": project.version,
"Specification-Vendor": "com.navercorp",
"Implementation-Title": artifactName,
"Implementation-Version": project.version,
"Implementation-Vendor": "com.navercorp"
)
}
}
3 changes: 3 additions & 0 deletions fixture-monkey-kotest/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=fixture-monkey-kotest
artifactName=Fixture Monkey Kotest
artifactDescription=Fixture Monkey supports Kotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Fixture Monkey
*
* Copyright (c) 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("TooManyFunctions")

package com.navercorp.fixturemonkey.kotest

import com.navercorp.fixturemonkey.ArbitraryBuilder
import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.api.type.TypeReference
import com.navercorp.fixturemonkey.api.type.Types
import com.navercorp.fixturemonkey.kotlin.giveMeBuilder
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import io.kotest.property.Arb
import io.kotest.property.arbitrary.arbitrary
import java.lang.reflect.AnnotatedType
import java.lang.reflect.Type
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.jvm.javaType
import kotlin.reflect.typeOf

@Suppress("UNCHECKED_CAST")
inline fun <reified T> FixtureMonkey.giveMeArb(): Arb<T> {
val type = typeOf<T>()

return if (type.isSubtypeOf(typeOf<ArbitraryBuilder<*>>())) {
val typeParameter = type.arguments[0]

arbitrary {
val javaType = typeParameter.type!!.javaType
giveMeBuilder(
object : TypeReference<T>() {
override fun getType(): Type {
return javaType
}

override fun getAnnotatedType(): AnnotatedType {
return Types.generateAnnotatedTypeWithoutAnnotation(javaType)
}
},
)
} as Arb<T>
} else {
arbitrary {
this@giveMeArb.giveMeOne()
}
}
}

inline fun <reified T> FixtureMonkey.giveMeArb(crossinline applyBuilder: (ArbitraryBuilder<T>) -> ArbitraryBuilder<T>): Arb<T> =
arbitrary {
applyBuilder.invoke(this@giveMeArb.giveMeBuilder()).sample()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Fixture Monkey
*
* Copyright (c) 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("TooManyFunctions", "unused")

package com.navercorp.fixturemonkey.kotest

import com.navercorp.fixturemonkey.FixtureMonkey
import io.kotest.property.PropTestConfig
import io.kotest.property.PropertyContext
import io.kotest.property.checkAll

suspend inline fun <reified A> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A) -> Unit,
) = checkAll(giveMeArb(), function)

suspend inline fun <reified A> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A) -> Unit,
) = checkAll(iterations, giveMeArb(), function)

suspend inline fun <reified A> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A) -> Unit,
) = checkAll(config, giveMeArb(), function)

suspend inline fun <reified A> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A) -> Unit,
) = checkAll(iterations, config, giveMeArb(), function)

suspend inline fun <reified A, reified B> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A, b: B) -> Unit,
) = checkAll(giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A, b: B) -> Unit,
) = checkAll(iterations, giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B) -> Unit,
) = checkAll(config, giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B) -> Unit,
) = checkAll(iterations, config, giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A, b: B, c: C) -> Unit,
) = checkAll(giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A, b: B, c: C) -> Unit,
) = checkAll(iterations, giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C) -> Unit,
) = checkAll(config, giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C) -> Unit,
) = checkAll(iterations, config, giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit,
) = checkAll(giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit,
) = checkAll(iterations, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit,
) = checkAll(config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D) -> Unit,
) = checkAll(iterations, config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit,
) = checkAll(giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit,
) = checkAll(iterations, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit,
) = checkAll(config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit,
) = checkAll(iterations, config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> FixtureMonkey.checkAll(
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit,
) = checkAll(giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> FixtureMonkey.checkAll(
iterations: Int,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit,
) = checkAll(iterations, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> FixtureMonkey.checkAll(
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit,
) = checkAll(config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)

suspend inline fun <reified A, reified B, reified C, reified D, reified E, reified F> FixtureMonkey.checkAll(
iterations: Int,
config: PropTestConfig,
noinline function: suspend PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit,
) = checkAll(iterations, config, giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), giveMeArb(), function)
Loading

0 comments on commit 2a60cbc

Please sign in to comment.