i-3: Add Mokkery as a mocking library #6

Merged
emil merged 6 commits from i-3-add-mock-library into main 2025-02-16 01:46:55 +00:00
4 changed files with 38 additions and 1 deletions

View File

@ -1,6 +1,12 @@
val versions = mapOf(
"kotlinx-datetime" to "0.6.2"
)
plugins { plugins {
alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary) alias(libs.plugins.androidLibrary)
id("dev.mokkery") version "2.0.0"
kotlin("plugin.allopen") version "2.1.10"
} }
kotlin { kotlin {
@ -25,7 +31,7 @@ kotlin {
sourceSets { sourceSets {
commonMain.dependencies { commonMain.dependencies {
//put your multiplatform dependencies here implementation("org.jetbrains.kotlinx:kotlinx-datetime:${versions["kotlinx-datetime"]}")
} }
commonTest.dependencies { commonTest.dependencies {
implementation(libs.kotlin.test) implementation(libs.kotlin.test)
@ -44,3 +50,8 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
} }
allOpen {
annotation("com.tle.astrologylibrary.OpenForMokkery")
// annotations("com.another.Annotation", "com.third.Annotation")
}

View File

@ -0,0 +1,3 @@
package com.tle.astrologylibrary
annotation class OpenForMokkery()

View File

@ -0,0 +1,7 @@
package com.tle.astrologylibrary
@OpenForMokkery
class A constructor()
@OpenForMokkery
class B constructor()
class Subject(val a: A, val b: B)

View File

@ -0,0 +1,16 @@
package com.tle.astrologylibrary
import dev.mokkery.mock
import kotlin.test.Test
import kotlin.test.assertEquals
class SubjectTest {
@Test
fun testCreateSubject() {
val a = mock<A> {}
val b = mock<B> {}
val subject = Subject(a, b)
assertEquals(a, subject.a)
assertEquals(b, subject.b)
}
}