Skip to content

Commit 1bbebe2

Browse files
committed
Add Android target to test-mokkery
1 parent 3ae7e60 commit 1bbebe2

File tree

7 files changed

+66
-2
lines changed

7 files changed

+66
-2
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ jobs:
1313
uses: actions/checkout@v4
1414
- name: Setup Gradle
1515
uses: gradle/actions/setup-gradle@v3
16+
- name: Setup Android SDK
17+
uses: android-actions/setup-android@v3
1618
- name: Gradle build
1719
run: ./gradlew build --no-daemon --stacktrace

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ buildscript {
1919
dependencies {
2020
classpath(":build-mokkery")
2121
classpath(libs.dokka.base)
22+
classpath(libs.agp)
2223
}
2324
}
2425

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ dokka = "2.1.0"
99
poko = "0.21.1"
1010
vanniktech-publish-plugin = "0.36.0"
1111
gradle-portal-publish = "2.0.0"
12+
agp = "9.0.1"
13+
androidx-runner = "1.7.0"
1214

1315
[plugins]
1416
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
1517
poko = { id = "dev.drewhamilton.poko", version.ref = "poko" }
1618
kotlinx-atomicfu = { id = "org.jetbrains.kotlinx.atomicfu", version.ref = "atomicfu" }
1719
kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
1820
gradle-portal-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-portal-publish" }
21+
agp-multiplatform = { id = "com.android.kotlin.multiplatform.library" }
1922

2023
[libraries]
2124
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
@@ -27,6 +30,7 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =
2730
kotlin-script-runtime = { module = "org.jetbrains.kotlin:kotlin-script-runtime", version.ref = "kotlin" }
2831
kotlin-test-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "kotlin" }
2932
kotlin-compiler-test-framework = { module = "org.jetbrains.kotlin:kotlin-compiler-internal-test-framework", version.ref = "kotlin" }
33+
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
3034

3135
vanniktech-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "vanniktech-publish-plugin" }
3236

@@ -39,3 +43,5 @@ dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka"
3943

4044
google-autoservice = { module = "com.google.auto.service:auto-service", version.ref = "google-autoservice"}
4145
google-autoservice-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "google-autoservice"}
46+
47+
androidx-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-runner" }

test-mokkery/build.gradle.kts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
2-
31
plugins {
42
id("mokkery-multiplatform")
3+
alias(libs.plugins.agp.multiplatform)
54
alias(libs.plugins.kotlin.allopen)
65
}
76

7+
kotlin {
8+
applyDefaultHierarchyTemplate()
9+
android {
10+
namespace = "dev.mokkery.test"
11+
compileSdk = 36
12+
minSdk = 21
13+
withHostTest { }
14+
withDeviceTestBuilder {
15+
sourceSetTreeName = "test"
16+
}
17+
}
18+
sourceSets {
19+
val jvmSharedTest by registering {
20+
dependsOn(commonTest.get())
21+
}
22+
jvmTest {
23+
dependsOn(jvmSharedTest.get())
24+
}
25+
getByName("androidHostTest") {
26+
dependsOn(jvmSharedTest.get())
27+
}
28+
getByName("androidDeviceTest") {
29+
dependsOn(jvmSharedTest.get())
30+
}
31+
}
32+
}
33+
834
allOpen {
935
annotation("dev.mokkery.test.OpenForMokkery")
1036
}
@@ -24,4 +50,6 @@ dependencies {
2450
commonMainImplementation(project(":mokkery-coroutines"))
2551
commonTestImplementation(kotlin("test"))
2652
commonTestImplementation(libs.kotlinx.coroutines.test)
53+
54+
"androidDeviceTestImplementation"(libs.androidx.runner)
2755
}

test-mokkery/src/jvmTest/kotlin/dev/mokkery/annotations/AnnotationsTest.kt renamed to test-mokkery/src/jvmSharedTest/kotlin/dev/mokkery/annotations/AnnotationsTest.kt

File renamed without changes.

test-mokkery/src/jvmTest/kotlin/dev/mokkery/test/Platform.jvm.kt renamed to test-mokkery/src/jvmSharedTest/kotlin/dev/mokkery/test/Platform.jvm.kt

File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dev.mokkery.types
2+
3+
import dev.mokkery.answering.SuperCall.Companion.original
4+
import dev.mokkery.answering.calls
5+
import dev.mokkery.answering.returns
6+
import dev.mokkery.every
7+
import dev.mokkery.mock
8+
import kotlin.test.Test
9+
import kotlin.test.assertContentEquals
10+
11+
class JavaSuperCallsTest {
12+
13+
private val list = mock<List<Int>>()
14+
15+
@Test
16+
fun test() {
17+
every(list::size::get) returns 3
18+
every { list.iterator() } returns iterator {
19+
yield(1)
20+
yield(2)
21+
yield(3)
22+
}
23+
every { list.spliterator() } calls original
24+
every { list.stream() } calls original
25+
assertContentEquals(arrayOf(1, 2, 3), list.stream().toArray())
26+
}
27+
}

0 commit comments

Comments
 (0)