Skip to content

Commit

Permalink
Fix Kotlin PrimaryConstructorArbitraryIntrospector generates concurre…
Browse files Browse the repository at this point in the history
…ntly
  • Loading branch information
seongahjo committed Sep 15, 2023
1 parent 97001a4 commit 54d9fbd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class PrimaryConstructorArbitraryIntrospector : ArbitraryIntrospector {
return ArbitraryIntrospectorResult.NOT_INTROSPECTED
}

val kotlinClass = Reflection.createKotlinClass(type) as KClass<*>
val constructor = CONSTRUCTOR_CACHE.computeIfAbsent(type) {
requireNotNull(kotlinClass.primaryConstructor) { "No kotlin primary constructor provided for $kotlinClass" }
}

return ArbitraryIntrospectorResult(
CombinableArbitrary.objectBuilder()
.properties(context.combinableArbitrariesByArbitraryProperty)
.build {
val kotlinClass = Reflection.createKotlinClass(type) as KClass<*>
val constructor = CONSTRUCTOR_CACHE.computeIfAbsent(type) {
requireNotNull(kotlinClass.primaryConstructor) { "No kotlin primary constructor provided for $kotlinClass" }
}

val arbitrariesByPropertyName = it.mapKeys { map -> map.key.objectProperty.property.name }

val map = mutableMapOf<KParameter, Any?>()
Expand Down
10 changes: 10 additions & 0 deletions fixture-monkey-tests/kotlin-concurrent-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id "org.jetbrains.kotlin.jvm" version "${KOTLIN_VERSION}"
}

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

testImplementation(project(":fixture-monkey-kotlin"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.navercorp.fixturemonkey.tests.concurrent.kotlin

import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import com.navercorp.fixturemonkey.tests.TestEnvironment
import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.RepeatedTest

class ConcurrentTest {
@RepeatedTest(TestEnvironment.TEST_COUNT)
fun test1() {
val actual: KotlinObject = SUT.giveMeOne<KotlinObject>()
then(actual).isNotNull()
}

@RepeatedTest(TestEnvironment.TEST_COUNT)
fun test2() {
val actual: KotlinObject = SUT.giveMeOne<KotlinObject>()
then(actual).isNotNull()
}

@RepeatedTest(TestEnvironment.TEST_COUNT)
fun test3() {
val actual: KotlinObject = SUT.giveMeOne<KotlinObject>()
then(actual).isNotNull()
}

data class KotlinObject(val value: String, val map: Map<String, String>)

companion object {
private val SUT = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=CONCURRENT
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include(
"fixture-monkey-tests:java-17-tests",
"fixture-monkey-tests:kotlin-tests",
"fixture-monkey-tests:java-tests",
"fixture-monkey-tests:java-concurrent-tests"
"fixture-monkey-tests:java-concurrent-tests",
"fixture-monkey-tests:kotlin-concurrent-tests"
)

0 comments on commit 54d9fbd

Please sign in to comment.