File tree Expand file tree Collapse file tree 7 files changed +72
-0
lines changed
subprojects/testing-with-mokkery
src/test/kotlin/org/sdkotlin/testing/mokkery Expand file tree Collapse file tree 7 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,5 @@ dependencies {
1616 implementation(libs.jvm.dependency.conflict.resolution.gradle.plugin.dependency)
1717 implementation(libs.kotlin.gradle.plugin.dependency)
1818 implementation(libs.ksp.gradle.plugin.dependency)
19+ implementation(libs.mokkery.gradle.plugin.dependency)
1920}
Original file line number Diff line number Diff line change 1+ plugins {
2+ kotlin(" jvm" )
3+ // Version catalog type-safe accessors and extension not yet available in
4+ // plugins block of precompiled script plugins:
5+ // https://github.com/gradle/gradle/issues/15383
6+ // alias(libs.plugins.mokkery.gradle.plugin)
7+ id(" dev.mokkery" )
8+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ ksp = "2.1.10-1.0.29" # Must match Kotlin version above.
1818mockito = " 5.15.2"
1919mockito-kotlin = " 2.2.0"
2020mockk = " 1.13.16"
21+ mokkery = " 2.6.1"
2122org-json = " 20250107"
2223slf4j = " 2.0.16"
2324versions-gradle-plugin = " 0.52.0"
@@ -170,6 +171,14 @@ version.ref = "mockk"
170171module = " io.mockk:mockk-dsl-jvm"
171172version.ref = " mockk"
172173
174+ [libraries .mokkery-core ]
175+ module = " dev.mokkery:mokkery-core"
176+ version.ref = " mokkery"
177+
178+ [libraries .mokkery-gradle-plugin-dependency ]
179+ module = " dev.mokkery:mokkery-gradle"
180+ version.ref = " mokkery"
181+
173182[libraries .org-json ]
174183module = " org.json:json"
175184version.ref = " org-json"
@@ -232,6 +241,10 @@ version.ref = "jvm-dependency-conflict-resolution"
232241id = " org.jetbrains.kotlin.jvm"
233242version.ref = " kotlin"
234243
244+ [plugins .mokkery-gradle-plugin ]
245+ id = " dev.mokkery"
246+ version.ref = " mokkery"
247+
235248[plugins .versions-gradle-plugin ]
236249id = " com.github.ben-manes.versions"
237250version.ref = " versions-gradle-plugin"
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ dependencies {
1717 api(libs.equalsverifier)
1818 api(libs.mockito)
1919 api(libs.mockito.kotlin)
20+ api(libs.mokkery.core)
2021 api(libs.bundles.mockk.jvm)
2122 }
2223}
Original file line number Diff line number Diff line change @@ -50,4 +50,5 @@ include("subprojects:ksp-builder-generator:processor")
5050include(" subprojects:ksp-builder-generator:processor:test-project" )
5151include(" subprojects:sorting-in-kotlin" )
5252include(" subprojects:tdd-in-kotlin" )
53+ include(" subprojects:testing-with-mokkery" )
5354include(" subprojects:typed-errors-in-kotlin" )
Original file line number Diff line number Diff line change 1+ plugins {
2+ id(" org.sdkotlin.buildlogic.kotlin-project" )
3+ id(" org.sdkotlin.buildlogic.test.unit-test-suite" )
4+ id(" org.sdkotlin.buildlogic.mokkery-project" )
5+ }
6+
7+ dependencies {
8+
9+ testImplementation(platform(" org.sdkotlin.platforms:test-platform" ))
10+
11+ testImplementation(libs.mokkery.core)
12+ }
Original file line number Diff line number Diff line change 1+ package org.sdkotlin.testing.mokkery
2+
3+ import dev.mokkery.answering.returns
4+ import dev.mokkery.every
5+ import dev.mokkery.mock
6+ import org.assertj.core.api.Assertions.assertThat
7+ import org.junit.jupiter.api.Test
8+
9+ interface ValueClassSuperType
10+
11+ @JvmInline
12+ value class ValueClass (val s : String ) : ValueClassSuperType
13+
14+ interface DataClassSuperType {
15+ val v: ValueClassSuperType
16+ }
17+
18+ @Suppress(" unused" ) // Not mockable by Mokkery unless all-opened.
19+ data class DataClass (
20+ override val v : ValueClassSuperType ,
21+ ) : DataClassSuperType
22+
23+ class MokkeryValueClassParameterTest {
24+
25+ @Test
26+ fun `test value class parameter` () {
27+
28+ val testValue = ValueClass (" testing" )
29+
30+ val mock = mock<DataClassSuperType > {
31+ every { v } returns testValue
32+ }
33+
34+ assertThat(mock.v).isEqualTo(testValue)
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments